| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Sticky positioned element should be observable by offsetTop and offsetLef
t</title> |
| 3 <link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" /> |
| 4 <meta name="assert" content="This test checks that a sticky positioned element |
| 5 should be observable by offsetTop/offsetLeft." /> |
| 6 |
| 7 <script src="/resources/testharness.js"></script> |
| 8 <script src="/resources/testharnessreport.js"></script> |
| 9 |
| 10 <style> |
| 11 body { |
| 12 margin: 0; |
| 13 } |
| 14 |
| 15 .container { |
| 16 position: relative; /* Required for offsetTop/offsetLeft tests. */ |
| 17 overflow: scroll; |
| 18 width: 200px; |
| 19 height: 200px; |
| 20 } |
| 21 |
| 22 .spacer { |
| 23 width: 2000px; |
| 24 height: 2000px; |
| 25 } |
| 26 |
| 27 .box { |
| 28 width: 100px; |
| 29 height: 100px; |
| 30 background-color: green; |
| 31 } |
| 32 |
| 33 .sticky { |
| 34 position: sticky; |
| 35 top: 50px; |
| 36 left: 20px; |
| 37 } |
| 38 </style> |
| 39 |
| 40 <div id="scroller1" class="container"> |
| 41 <div class="spacer"></div> |
| 42 </div> |
| 43 |
| 44 <script> |
| 45 test(() => { |
| 46 var scroller = document.getElementById('scroller1'); |
| 47 scroller.scrollTop = 100; |
| 48 scroller.scrollLeft = 75; |
| 49 |
| 50 var sticky = document.createElement('div'); |
| 51 sticky.className = 'sticky box'; |
| 52 scroller.insertBefore(sticky, scroller.querySelector('.spacer')); |
| 53 |
| 54 assert_equals(sticky.offsetTop, scroller.scrollTop + 50); |
| 55 assert_equals(sticky.offsetLeft, scroller.scrollLeft + 20); |
| 56 }, 'offsetTop/offsetLeft should be correct for sticky after script insertion'); |
| 57 </script> |
| 58 |
| 59 <div id="scroller2" class="container"> |
| 60 <div id="sticky2" class="sticky box"></div> |
| 61 <div class="spacer"></div> |
| 62 </div> |
| 63 |
| 64 <script> |
| 65 test(function() { |
| 66 var scroller = document.getElementById('scroller2'); |
| 67 var sticky = document.getElementById('sticky2'); |
| 68 scroller.scrollTop = 100; |
| 69 scroller.scrollLeft = 75; |
| 70 |
| 71 var div = document.createElement('div'); |
| 72 div.style.height = '65px'; |
| 73 scroller.insertBefore(div, sticky); |
| 74 |
| 75 assert_equals(sticky.offsetTop, scroller.scrollTop + 50); |
| 76 assert_equals(sticky.offsetLeft, scroller.scrollLeft + 20); |
| 77 }, 'offsetTop/offsetLeft should be correct for sticky after script-caused layout
'); |
| 78 </script> |
| OLD | NEW |