4 <title>Timeline offset in Animation Keyframes
</title>
5 <link rel=
"help" href=
"https://w3c.github.io/csswg-drafts/scroll-animations-1/#named-range-keyframes">
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>
11 @keyframes fade-in-out-animation {
12 entry
0%, exit
100% { opacity:
0 }
13 entry
100%, exit
0% { opacity:
1 }
17 background-color: rgba(
0,
0,
255);
20 view-timeline-name: foo;
21 animation: linear
1s both fade-in-out-animation;
22 animation-timeline: foo;
26 border:
5px solid black;
38 <body onload=
"runTests()">
40 <div class=
"spacer"></div>
41 <div id=
"subject"></div>
42 <div class=
"spacer"></div>
46 <script type=
"text/javascript">
47 setup(assert_implements_animation_timeline
);
50 promise_test(async t
=> {
51 // scrollTop=200 to 400 is the entry range
52 container
.scrollTop
= 200;
53 await
waitForNextFrame();
54 const anim
= document
.getAnimations()[0];
55 assert_equals(getComputedStyle(subject
).opacity
, '0',
56 'Effect at entry 0%');
58 container
.scrollTop
= 300;
59 await
waitForNextFrame();
60 assert_equals(getComputedStyle(subject
).opacity
, '0.5',
61 'Effect at entry 50%');
63 container
.scrollTop
= 400;
64 await
waitForNextFrame();
65 assert_equals(getComputedStyle(subject
).opacity
, '1',
66 'Effect at entry 100%');
68 // scrollTop=600-800 is the exit range
69 container
.scrollTop
= 600;
70 await
waitForNextFrame();
71 assert_equals(getComputedStyle(subject
).opacity
, '1',
74 container
.scrollTop
= 700;
75 await
waitForNextFrame();
76 assert_equals(getComputedStyle(subject
).opacity
, '0.5',
77 'Effect at exit 50%');
79 container
.scrollTop
= 800;
80 await
waitForNextFrame();
81 assert_equals(getComputedStyle(subject
).opacity
, '0',
82 'Effect at exit 100%');
84 // First change scrollTop so that you are at entry 100%, then resize the
85 // container in a way that scrollTop is the same, but now the animation is
86 // at entry 50% and check opacity. After changing the height of container,
87 // scrollTop=300-500 is the entry range
88 container
.scrollTop
= 400;
89 await
waitForNextFrame();
90 assert_equals(getComputedStyle(subject
).opacity
, '1',
91 'Effect at entry 100% (post resize)');
93 container
.style
.height
= '300px';
94 await
waitForNextFrame();
95 assert_equals(getComputedStyle(subject
).opacity
, '0.5',
96 'Effect at entry 50% (post resize)');
98 // After changing the height of container, scrollTop=600-800 is still the
100 container
.scrollTop
= 700;
101 await
waitForNextFrame();
102 assert_equals(getComputedStyle(subject
).opacity
, '0.5',
103 'Effect at exit 50% (post resize)');