Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE html>
<html>
<head>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
</head>
<body>
<div id="event-target">Click me!</div>
<div id="animation-target">Watch me!</div>
<script>
promise_test(async (test) => {
const eventTarget = document.getElementById("event-target");
const animationTarget = document.getElementById("animation-target");
const ANIMATION_DURATION_MS = 100000;
const animation = new Animation(
new KeyframeEffect(
animationTarget,
[
{ transform: "translateY(0)" },
{ transform: "translateY(3rem)" },
],
{ duration: ANIMATION_DURATION_MS, fill: "both" }
));
const trigger = new EventTrigger({
behavior: "state",
eventType: "click",
eventTarget: eventTarget
});
trigger.addAnimation(animation);
await waitForAnimationFrames(1);
assert_equals(animation.playState, "idle", "animation is idle");
await test_driver.click(eventTarget);
await waitForAnimationFrames(1);
assert_equals(animation.playState, "running", "animation is running");
await test_driver.click(eventTarget);
await waitForAnimationFrames(1);
assert_equals(animation.playState, "paused", "animation is paused");
await test_driver.click(eventTarget);
await waitForAnimationFrames(1);
assert_equals(animation.playState, "running", "animation is running");
}, "Basic event-based animation-trigger with 'state' behavior");
</script>
</body>
</html>