snap-intended-direction.html (1517B)
1 <!DOCTYPE html> 2 <title>`intended direction` scroll snaps only at points ahead of the scroll direction</title> 3 <link rel="help" href="https://drafts.csswg.org/css-scroll-snap-1/#scroll-snap-type" /> 4 <link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1766805"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <style> 8 div { 9 position: absolute; 10 margin: 0px; 11 } 12 #scroller { 13 width: 200px; 14 height: 100px; 15 overflow: scroll; 16 scroll-snap-type: x mandatory; 17 } 18 .snap { 19 scroll-snap-align: start; 20 background: green; 21 } 22 </style> 23 24 <div id="scroller"> 25 <div style="width: 2000px; height: 100px;"></div> 26 <div class="snap" style="left: 0px; width: 20px; height: 100px;">1</div> 27 <div class="snap" style="left: 100px; width: 20px; height: 100px;">2</div> 28 <div class="snap" style="left: 120px; width: 20px; height: 100px;">3</div> 29 <div class="snap" style="left: 300px; width: 20px; height: 100px;">4</div> 30 <div class="snap" style="left: 400px; width: 20px; height: 100px;">5</div> 31 </div> 32 33 <script> 34 test(() => { 35 scroller.scrollBy(10, 0); 36 assert_equals(scroller.scrollLeft, 100); 37 38 scroller.scrollBy(10, 0); 39 assert_equals(scroller.scrollLeft, 120); 40 41 scroller.scrollBy(10, 0); 42 // Snaps to the next snap point even if the previous snap point is closer to 43 // the current position. 44 assert_equals(scroller.scrollLeft, 300); 45 }, "`intended direction` scroll snaps only at points ahead of the scroll " + 46 "direction"); 47 48 </script>