OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script> |
| 3 if (window.internals) { |
| 4 internals.settings.setCSSStickyPositionEnabled(true); |
| 5 } |
| 6 </script> |
| 7 |
| 8 <html> |
| 9 <head> |
| 10 <style> |
| 11 body { |
| 12 margin: 0; |
| 13 height: 2000px; |
| 14 overflow: hidden; /* hide scrollbars */ |
| 15 } |
| 16 |
| 17 .group { |
| 18 display: inline-block; |
| 19 position: relative; |
| 20 width: 180px; |
| 21 height: 500px; |
| 22 } |
| 23 |
| 24 .container { |
| 25 width: 150px; |
| 26 height: 400px; |
| 27 border: 2px solid black; |
| 28 padding: 5px; |
| 29 } |
| 30 |
| 31 .box { |
| 32 width: 120px; |
| 33 height: 120px; |
| 34 } |
| 35 |
| 36 .sticky { |
| 37 position: sticky; |
| 38 top: 10px; |
| 39 background-color: green; |
| 40 } |
| 41 |
| 42 .indicator { |
| 43 position: absolute; |
| 44 top: 0; |
| 45 left: 37px; |
| 46 background-color: red; |
| 47 } |
| 48 </style> |
| 49 <script> |
| 50 function doTest() |
| 51 { |
| 52 window.scrollTo(0, 300); |
| 53 } |
| 54 window.addEventListener('load', doTest, false); |
| 55 </script> |
| 56 </head> |
| 57 <body> |
| 58 <!-- auto margins --> |
| 59 <div class="group"> |
| 60 <div class="indicator box" style="top: 110px;"></div> |
| 61 <div class="container"> |
| 62 <div class="sticky box" style="margin: auto;"></div> |
| 63 </div> |
| 64 </div> |
| 65 |
| 66 <!-- px margins --> |
| 67 <div class="group"> |
| 68 <div class="indicator box" style="top: 37px;"></div> |
| 69 <div class="container"> |
| 70 <div class="sticky box" style="margin: 20px;"></div> |
| 71 </div> |
| 72 </div> |
| 73 |
| 74 <!-- % margins --> |
| 75 <div class="group"> |
| 76 <div class="indicator box" style="top: 37px;"></div> |
| 77 <div class="container"> |
| 78 <div class="sticky box" style="margin: 20%;"></div> |
| 79 </div> |
| 80 </div> |
| 81 |
| 82 <!-- % margins --> |
| 83 <div class="group"> |
| 84 <div class="indicator box" style="top: 37px;"></div> |
| 85 <div class="container" style="width: 200px;"> |
| 86 <div class="sticky box" style="margin: 20%;"></div> |
| 87 </div> |
| 88 </div> |
| 89 </body> |
| 90 </html> |
OLD | NEW |