Revision control

1
<!DOCTYPE html>
2
<body>
3
<style>
4
body, #cover {
5
background-color: green;
6
}
7
8
#target, #cover {
9
position: absolute;
10
top: 0;
11
left: 0;
12
height: 100px;
13
}
14
15
#target {
16
width: 100px;
17
background-color: red;
18
}
19
20
/* This element covers the first half of the area traveled by the animated target. If the animation did not
21
respect the playbackRate, then red would appear since the animated target would travel to the right of
22
the cover element. */
23
#cover {
24
left: 100px;
25
width: 200px;
26
}
27
28
</style>
29
<div id="target"></div>
30
<div id="cover"></div>
31
<script>
32
33
(async () => {
34
if (window.testRunner)
35
testRunner.waitUntilDone();
36
37
// Start an animation.
38
const animation = document.getElementById("target").animate({ transform: ["translateX(100px)", "translateX(300px)"] }, { duration: 1000, fill: "both" });
39
40
// Seek it to its halfway point, the target should align with the right edge of the cover.
41
animation.currentTime = animation.effect.getTiming().duration / 2;
42
43
// Make it play backwards.
44
animation.playbackRate = -1;
45
46
// Wait a few frames.
47
await animation.ready;
48
await new Promise(requestAnimationFrame);
49
await new Promise(requestAnimationFrame);
50
await new Promise(requestAnimationFrame);
51
52
// At this point, if the target were ignoring the playbackRate, it would peek a little to the right of the cover.
53
if (window.testRunner)
54
testRunner.notifyDone();
55
})();
56
57
</script>
58
</body>