opt-out.html (2052B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <style> 5 6 body { height: 2000px; overflow-anchor: none; } 7 #scroller { overflow: scroll; width: 500px; height: 300px; } 8 .anchor { 9 position:relative; height: 100px; width: 150px; 10 background-color: #afa; border: 1px solid gray; 11 } 12 #forceScrolling { height: 500px; background-color: #fcc; } 13 14 </style> 15 <div id="outerChanger"></div> 16 <div id="outerAnchor" class="anchor"></div> 17 <div id="scroller"> 18 <div id="innerChanger"></div> 19 <div id="innerAnchor" class="anchor"></div> 20 <div id="forceScrolling"></div> 21 </div> 22 <script> 23 24 // Tests that scroll anchoring can be disabled per-scroller with the 25 // overflow-anchor property. 26 27 var divScroller = document.querySelector("#scroller"); 28 var docScroller = document.scrollingElement; 29 var innerChanger = document.querySelector("#innerChanger"); 30 var outerChanger = document.querySelector("#outerChanger"); 31 32 function setup() { 33 divScroller.scrollTop = 100; 34 docScroller.scrollTop = 100; 35 innerChanger.style.height = "200px"; 36 outerChanger.style.height = "150px"; 37 } 38 39 function reset() { 40 document.body.style.overflowAnchor = ""; 41 divScroller.style.overflowAnchor = ""; 42 divScroller.scrollTop = 0; 43 docScroller.scrollTop = 0; 44 innerChanger.style.height = ""; 45 outerChanger.style.height = ""; 46 } 47 48 test(() => { 49 setup(); 50 51 assert_equals(divScroller.scrollTop, 300, 52 "Scroll anchoring should apply to #scroller."); 53 54 assert_equals(docScroller.scrollTop, 100, 55 "Scroll anchoring should not apply to the document scroller."); 56 57 reset(); 58 }, "Disabled on document, enabled on div."); 59 60 test(() => { 61 document.body.style.overflowAnchor = "auto"; 62 divScroller.style.overflowAnchor = "none"; 63 setup(); 64 65 assert_equals(divScroller.scrollTop, 100, 66 "Scroll anchoring should not apply to #scroller."); 67 68 assert_equals(docScroller.scrollTop, 250, 69 "Scroll anchoring should apply to the document scroller."); 70 71 reset(); 72 }, "Enabled on document, disabled on div."); 73 74 </script>