event-trigger-once.tentative.html (1937B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <link rel="help" href="https://drafts.csswg.org/web-animations-2#animation-trigger"> 5 <script src="/resources/testdriver.js"></script> 6 <script src="/resources/testdriver-vendor.js"></script> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="/web-animations/testcommon.js"></script> 10 </head> 11 <body> 12 <div id="event-target">Click me!</div> 13 14 <div id="animation-target">Watch me!</div> 15 <script> 16 promise_test(async (test) => { 17 const eventTarget = document.getElementById("event-target"); 18 const animationTarget = document.getElementById("animation-target"); 19 const ANIMATION_DURATION_MS = 10000; 20 const animation = new Animation( 21 new KeyframeEffect( 22 animationTarget, 23 [ 24 { transform: "translateY(0)" }, 25 { transform: "translateY(3rem)" }, 26 ], 27 { duration: ANIMATION_DURATION_MS, fill: "both" } 28 )); 29 const trigger = new EventTrigger({ 30 eventType: "click", 31 eventTarget: eventTarget 32 }); 33 trigger.addAnimation(animation, "play-once"); 34 await waitForAnimationFrames(1); 35 assert_equals(animation.playState, "idle", "animation is idle"); 36 await test_driver.click(eventTarget); 37 await waitForAnimationFrames(1); 38 assert_equals(animation.playState, "running", "animation is running"); 39 animation.finish(); 40 await waitForAnimationFrames(1); 41 assert_equals(animation.playState, "finished", "animation is finished"); 42 await test_driver.click(eventTarget); 43 await waitForAnimationFrames(1); 44 assert_equals(animation.playState, "finished", "animation is still finished"); 45 }, "Basic event-based animation-trigger with 'once' behavior"); 46 </script> 47 </body> 48 </html>