Chromium Code Reviews| 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 id="spacer1" 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, document.getElementById('spacer1')); | |
| 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 id="spacer2" 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 scroller.append(document.createElement('div')); | |
| 72 | |
| 73 assert_equals(sticky.offsetTop, scroller.scrollTop + 50); | |
| 74 assert_equals(sticky.offsetLeft, scroller.scrollLeft + 20); | |
| 75 }, 'offsetTop/offsetLeft should be correct for sticky after script-caused layout '); | |
|
flackr
2017/06/07 18:32:56
These seem like they should have all of the same u
smcgruer
2017/06/07 20:57:32
I'm not convinced by the code savings here. How st
flackr
2017/06/08 19:38:03
It's not code savings but completeness - these sho
| |
| 76 | |
| 77 </script> | |
| OLD | NEW |