anchor-scroll-position-try-004.html (2102B)
1 <!DOCTYPE html> 2 <title>Tests position fallback with scrollers with mixed writing modes</title> 3 <link rel="author" href="mailto:xiaochengh@chromium.org"> 4 <link rel="help" href="https://drafts.csswg.org/css-anchor-1/#scroll"> 5 <link rel="help" href="https://drafts.csswg.org/css-anchor-1/#fallback-apply"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="support/test-common.js"></script> 9 10 <style> 11 body { 12 margin: 0; 13 } 14 15 #vrl-scroller { 16 writing-mode: vertical-rl; 17 overflow-x: scroll; 18 width: calc(100vw - 90px); 19 height: 400px; 20 outline: 1px solid black; 21 } 22 23 #anchor { 24 anchor-name: --a; 25 width: 100px; 26 height: 100px; 27 margin-left: 120lvw; 28 background: orange; 29 } 30 31 #anchored { 32 position: fixed; 33 width: 100px; 34 height: 100px; 35 background: green; 36 position-anchor: --a; 37 position-try-fallbacks: --pf1, --pf2; 38 /* Top of the anchor */ 39 bottom: anchor(top); 40 left: anchor(left); 41 } 42 43 @position-try --pf1 { 44 /* Bottom of the anchor */ 45 top: anchor(bottom); 46 bottom: auto; 47 } 48 @position-try --pf2 { 49 /* Left of the anchor */ 50 top: anchor(top); 51 right: anchor(left); 52 bottom: auto; 53 left: auto; 54 } 55 </style> 56 57 <div style="height: 200px"></div> 58 <div id="vrl-scroller"> 59 <div id="anchor"></div> 60 </div> 61 <div style="height: 120lvh"></div> 62 <div id="anchored"></div> 63 64 <script> 65 promise_test(async () => { 66 await waitUntilNextAnimationFrame(); 67 assert_fallback_position(anchored, anchor, 'top'); 68 }, 'Should use the first fallback position at the initial scroll offsets'); 69 70 promise_test(async () => { 71 document.documentElement.scrollTop = 101; 72 await waitUntilNextAnimationFrame(); 73 assert_fallback_position(anchored, anchor, 'bottom'); 74 }, 'Should use the second fallback position after scrolling viewport down'); 75 76 promise_test(async () => { 77 let vrlScroller = document.getElementById('vrl-scroller'); 78 vrlScroller.scrollLeft = -100; 79 await waitUntilNextAnimationFrame(); 80 assert_fallback_position(anchored, anchor, 'left'); 81 }, 'Should use the third fallback position after scrolling the vrl scroller left'); 82 </script>