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 <title>Animation range and delay
</title>
13 <style type=
"text/css">
25 border: 10px solid lightgray
;
30 timeline-scope: --sibling
;
38 background-color: blue
;
39 view-timeline: --sibling block
;
48 background-color: green
;
49 animation: anim auto both linear
;
50 /* using document timeline by default */
51 animation-range-start: contain
0%;
52 animation-range-end: contain
100%;
53 view-timeline: --target block
;
56 #target.with-view-timeline
{
57 animation-timeline: --target
;
59 #target.with-view-timeline
.retarget
{
60 animation-timeline: --sibling
;
65 <div id=
"sibling"></div>
66 <div id=
"target"></div>
69 <script type=
"text/javascript">
70 async
function runTest() {
71 promise_test(async t
=> {
72 await
waitForNextFrame();
73 const anim
= document
.getAnimations()[0];
75 await
waitForNextFrame();
77 // Initially using a document timeline, so the keyframes should be
79 let frames
= anim
.effect
.getKeyframes();
81 { offset
: { rangeName
: 'cover', offset
: CSS
.percent(0) },
82 computedOffset
: null, easing
: "linear", composite
: "auto",
83 marginLeft
: "0px", opacity
: "0" },
84 { offset
: { rangeName
: 'cover', offset
: CSS
.percent(100) },
85 computedOffset
: null, easing
: "linear", composite
: "auto",
86 marginRight
: "0px", opacity
: "1" }
88 assert_frame_lists_equal(frames
, expected
);
89 // Once a view-timeline is added, the kefyrames must update to reflect
90 // the new keyframe offsets.
91 target
.classList
.add('with-view-timeline');
92 assert_equals(getComputedStyle(target
).animationTimeline
, '--target',
93 'Switch to view timeline');
94 await
waitForNextFrame();
96 frames
= anim
.effect
.getKeyframes();
98 { offset
: 0, computedOffset
: 0, easing
: "linear", composite
: "replace",
99 marginRight
: "10px" },
100 { offset
: 1, computedOffset
: 1, easing
: "linear", composite
: "replace",
101 marginLeft
: "10px" },
102 { offset
: { rangeName
: 'cover', offset
: CSS
.percent(0) },
103 computedOffset
: -1, easing
: "linear", composite
: "auto",
104 marginLeft
: "0px", opacity
: "0" },
105 { offset
: { rangeName
: 'cover', offset
: CSS
.percent(100) },
106 computedOffset
: 2, easing
: "linear", composite
: "auto",
107 marginRight
: "0px", opacity
: "1" },
109 assert_frame_lists_equal(frames
, expected
);
111 target
.classList
.add('retarget');
112 assert_equals(getComputedStyle(target
).animationTimeline
, '--sibling',
113 'Switch to another view timeline');
114 await
waitForNextFrame();
115 frames
= anim
.effect
.getKeyframes();
117 { offset
: 0, computedOffset
: 0, easing
: "linear", composite
: "replace",
118 marginRight
: "10px" },
119 { offset
: 1, computedOffset
: 1, easing
: "linear", composite
: "replace",
120 marginLeft
: "10px" },
121 { offset
: { rangeName
: 'cover', offset
: CSS
.percent(0) },
122 computedOffset
: -1/3, easing
: "linear",
123 composite
: "auto", marginLeft
: "0px", opacity
: "0" },
124 { offset
: { rangeName
: 'cover', offset
: CSS
.percent(100) },
125 computedOffset
: 4/3, easing
: "linear", composite
: "auto",
126 marginRight
: "0px", opacity
: "1" },
128 assert_frame_lists_equal(frames
, expected
);
130 target
.classList
.toggle('with-view-timeline');
131 assert_equals(getComputedStyle(target
).animationTimeline
, 'auto',
132 'Switch back to document timeline');
133 frames
= anim
.effect
.getKeyframes();
135 { offset
: { rangeName
: 'cover', offset
: CSS
.percent(0) },
136 computedOffset
: null, easing
: "linear", composite
: "auto",
137 marginLeft
: "0px", opacity
: "0" },
138 { offset
: { rangeName
: 'cover', offset
: CSS
.percent(100) },
139 computedOffset
: null, easing
: "linear", composite
: "auto",
140 marginRight
: "0px", opacity
: "1" }
142 assert_frame_lists_equal(frames
, expected
);
143 }, 'getKeyframes with timeline-offsets');
146 window
.onload
= runTest
;