| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <style> | |
| 3 .scroller { | |
| 4 background-color: red; | |
| 5 border: 1px solid black; | |
| 6 width: 200px; | |
| 7 height: 200px; | |
| 8 margin-top: 10px; | |
| 9 outline: 2px solid black; | |
| 10 overflow: hidden; /* hide scrollbars */ | |
| 11 } | |
| 12 | |
| 13 .sticky { | |
| 14 background-color: green; | |
| 15 display: inline-block; | |
| 16 margin-top: 200px; | |
| 17 position: relative; | |
| 18 top: 0px; | |
| 19 width: 200px; | |
| 20 height: 200px; | |
| 21 } | |
| 22 | |
| 23 </style> | |
| 24 <script> | |
| 25 function doTest() | |
| 26 { | |
| 27 var stickyObjects = document.querySelectorAll('.sticky'); | |
| 28 for (var i = 0; i < stickyObjects.length; i++) { | |
| 29 stickyObjects[i].style.marginTop = '0'; | |
| 30 } | |
| 31 } | |
| 32 window.addEventListener('load', doTest, false); | |
| 33 </script> | |
| 34 <div class="scroller"> | |
| 35 <div class="sticky"></div> | |
| 36 </div> | |
| 37 <div class="scroller"> | |
| 38 <div> | |
| 39 <div class="sticky"></div> | |
| 40 </div> | |
| 41 </div> | |
| OLD | NEW |