animation-range-normal-matches-cover.html (2989B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <link rel="help" src="https://drafts.csswg.org/scroll-animations-1/#named-timeline-range"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="/web-animations/testcommon.js"></script> 9 <script src="support/testcommon.js"></script> 10 <script src="/scroll-animations/scroll-timelines/testcommon.js"></script> 11 <title>Animation range 'normal' is equivalent to animation range 'cover'</title> 12 </head> 13 <style type="text/css"> 14 @keyframes anim-1 { 15 from { background-color: blue; } 16 to { background-color: white; } 17 } 18 @keyframes anim-2 { 19 from { opacity: 0.3; } 20 to { opacity: 1; } 21 } 22 #scroller { 23 border: 10px solid lightgray; 24 overflow-y: scroll; 25 overflow-x: hidden; 26 width: 300px; 27 height: 200px; 28 } 29 #target { 30 margin-top: 800px; 31 margin-bottom: 800px; 32 margin-left: 10px; 33 margin-right: 10px; 34 width: 100px; 35 height: 100px; 36 z-index: -1; 37 background-color: green; 38 animation: anim-1 auto linear, anim-2 auto linear; 39 animation-range: normal, cover; 40 view-timeline: --t1; 41 animation-timeline: --t1, --t1; 42 } 43 </style> 44 <body> 45 <div id="scroller"> 46 <div id="target"></div> 47 </div> 48 </body> 49 <script type="text/javascript"> 50 async function runTest() { 51 function assert_range_equals(actual, expected) { 52 if (typeof expected == 'string') { 53 assert_equals(actual, expected); 54 } else { 55 assert_equals(actual.rangeName, expected.rangeName); 56 assert_equals(actual.offset.value, expected.offset.value); 57 } 58 } 59 60 promise_test(async t => { 61 anims = target.getAnimations(); 62 assert_equals(anims.length, 2, "Expecting 2 animations"); 63 await anims[0].ready; 64 await anims[1].ready; 65 66 assert_range_equals(anims[0].rangeStart, "normal"); 67 assert_range_equals(anims[0].rangeEnd, "normal"); 68 assert_range_equals(anims[1].rangeStart, 69 { rangeName: 'cover', offset: CSS.percent(0) }); 70 assert_range_equals(anims[1].rangeEnd, 71 { rangeName: 'cover', offset: CSS.percent(100) }); 72 73 await runAndWaitForFrameUpdate(() => { 74 scroller.scrollTop = 600; // Start boundary for cover range. 75 }); 76 77 assert_percents_equal(anims[0].currentTime, 0, 78 'currentTime at start of normal range'); 79 assert_percents_equal(anims[1].currentTime, 0, 80 'currentTime at cover 0%'); 81 82 scroller.scrollTop = 900; // End boundary for cover range. 83 await waitForNextFrame(); 84 85 assert_percents_equal(anims[0].currentTime, 100, 86 'currentTime at end of normal range'); 87 assert_percents_equal(anims[1].currentTime, 100, 88 'currentTime at cover 100%'); 89 }, 'Changing the animation range updates the play state'); 90 } 91 92 window.onload = runTest; 93 </script>