change-animation-range-updates-play-state.html (2732B)
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="/web-animations/resources/keyframe-utils.js"></script> 11 <script src="/scroll-animations/scroll-timelines/testcommon.js"></script> 12 <title>Animation range updates play state</title> 13 </head> 14 <style type="text/css"> 15 @keyframes anim { 16 from { background-color: blue; } 17 to { background-color: white; } 18 } 19 #scroller { 20 border: 10px solid lightgray; 21 overflow-y: scroll; 22 overflow-x: hidden; 23 width: 300px; 24 height: 200px; 25 } 26 #target { 27 margin-top: 800px; 28 margin-bottom: 800px; 29 margin-left: 10px; 30 margin-right: 10px; 31 width: 100px; 32 height: 100px; 33 z-index: -1; 34 background-color: green; 35 animation: anim auto both linear; 36 animation-timeline: --t1; 37 view-timeline: --t1; 38 } 39 </style> 40 <body> 41 <div id="scroller"> 42 <div id="target"></div> 43 </div> 44 </body> 45 <script type="text/javascript"> 46 async function runTest() { 47 promise_test(async t => { 48 anim = target.getAnimations()[0]; 49 await anim.ready; 50 51 // Cover range = 600px to 900px 52 53 scroller.scrollTop = 750; 54 await waitForNextFrame(); 55 56 // Animation is running in the active phase. 57 await runAndWaitForFrameUpdate(() => { 58 anim.rangeStart = 'contain 0%'; // 700px 59 anim.rangeEnd = 'contain 100%'; // 800px 60 }); 61 assert_equals(anim.playState, 'running'); 62 assert_percents_equal(anim.startTime, 100/3); 63 assert_percents_equal(anim.currentTime, 100/6); 64 65 // Animation in the after phase and switches to the finished state. 66 await runAndWaitForFrameUpdate(() => { 67 anim.rangeStart = 'entry 0%'; // 600px 68 anim.rangeEnd = 'entry 100%'; // 700px 69 }); 70 assert_equals(anim.playState, 'finished'); 71 assert_percents_equal(anim.startTime, 0); 72 // In the after phase, so current time is clamped. 73 assert_percents_equal(anim.currentTime, 100/3); 74 75 // Animation in the before phase and switches back to the running state. 76 await runAndWaitForFrameUpdate(() => { 77 anim.rangeStart = 'exit 0%'; // 800px 78 anim.rangeEnd = 'exit 100%'; // 900px 79 }); 80 assert_equals(anim.playState, 'running'); 81 assert_percents_equal(anim.startTime, 200/3); 82 assert_percents_equal(anim.currentTime, -100/6); 83 84 }, 'Changing the animation range updates the play state'); 85 } 86 87 window.onload = runTest; 88 </script>