summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/scroll-animations/css/view-timeline-animation.html
blob: 1bf034a742f3b30be5070b78536614c1b53823fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<title>Animations using view-timeline</title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
<link rel="help" src="https://drafts.csswg.org/scroll-animations-1/#view-timelines-named">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
<script src="support/testcommon.js"></script>
<style>
  @keyframes anim {
    from { z-index: 0; }
    to { z-index: 100; }
  }
  .vertical-scroller {
    overflow: auto;
    width: 100px;
    height: 100px;
  }
  .vertical-scroller > div {
    height: 50px;
    z-index: -1;
  }
  .horizontal-scroller {
    overflow: auto;
    width: 100px;
    height: 100px;
    writing-mode: vertical-lr;
  }
  .horizontal-scroller > div {
    width: 50px;
    z-index: -1;
  }
</style>
<main id=main></main>
<script>
  setup(assert_implements_animation_timeline);

  function inflate(t, template) {
    t.add_cleanup(() => main.replaceChildren());
    main.append(template.content.cloneNode(true));
  }
  async function scrollTop(e, value) {
    e.scrollTop = value;
    await waitForNextFrame();
  }
  async function scrollLeft(e, value) {
    e.scrollLeft = value;
    await waitForNextFrame();
  }
</script>

<template id=default_view_timeline>
  <style>
    #target {
      view-timeline: --t1;
      animation: anim 1s linear forwards;
      animation-timeline: --t1;
    }
  </style>
  <div id=scroller class=vertical-scroller>
    <div></div>           <!-- [0px,   50px]  -->
    <div></div>           <!-- [50px,  100px] -->
    <div></div>           <!-- [100px, 150px] -->
    <div id=target></div> <!-- [150px, 200px] -->
    <div></div>           <!-- [200px, 250px] -->
    <div></div>           <!-- [250px, 300px] -->
    <div></div>           <!-- [300px, 350px] -->
  </div>
</template>
<script>
  promise_test(async (t) => {
    inflate(t, default_view_timeline);
    assert_equals(getComputedStyle(target).zIndex, '-1');
    await scrollTop(scroller, 25);
    assert_equals(getComputedStyle(target).zIndex, '-1');
    await scrollTop(scroller, 50); // 0% (enter 0%)
    assert_equals(getComputedStyle(target).zIndex, '0');
    await scrollTop(scroller, 125); // 50%
    assert_equals(getComputedStyle(target).zIndex, '50');
    await scrollTop(scroller, 200); // 100% (exit 100%)
    assert_equals(getComputedStyle(target).zIndex, '100');
    document.getAnimations()[0].effect.updateTiming( { fill: 'none' });
    assert_equals(getComputedStyle(target).zIndex, '-1');
  }, 'Default view-timeline');
</script>

<template id=horizontal_timeline>
  <style>
    #target {
      view-timeline: --t1 x;
      animation: anim 1s linear forwards;
      animation-timeline: --t1;
    }
  </style>
  <div id=scroller class=horizontal-scroller>
    <div></div>           <!-- [0px,   50px]  -->
    <div></div>           <!-- [50px,  100px] -->
    <div></div>           <!-- [100px, 150px] -->
    <div id=target></div> <!-- [150px, 200px] -->
    <div></div>           <!-- [200px, 250px] -->
    <div></div>           <!-- [250px, 300px] -->
    <div></div>           <!-- [300px, 350px] -->
  </div>
</template>
<script>
  promise_test(async (t) => {
    inflate(t, horizontal_timeline);
    assert_equals(getComputedStyle(target).zIndex, '-1');
    await scrollLeft(scroller, 25);
    assert_equals(getComputedStyle(target).zIndex, '-1');
    await scrollLeft(scroller, 50); // 0% (enter 0%)
    assert_equals(getComputedStyle(target).zIndex, '0');
    await scrollLeft(scroller, 125); // 50%
    assert_equals(getComputedStyle(target).zIndex, '50');
    await scrollLeft(scroller, 200); // 100% (exit 100%)
    assert_equals(getComputedStyle(target).zIndex, '100');
    document.getAnimations()[0].effect.updateTiming( { fill: 'none' });
    assert_equals(getComputedStyle(target).zIndex, '-1');
  }, 'Horizontal view-timeline');
</script>

<template id=multiple_timelines>
  <style>
    #timelines {
      view-timeline: --tv y, --th x;
      background-color: red;
    }
    #scroller {
      width: 100px;
      height: 100px;
      overflow: hidden;
      display: grid;
      grid-template-columns: 50px 50px 50px 50px 50px 50px 50px;
      grid-template-row: 50px 50px 50px 50px 50px 50px 50px;
      timeline-scope: --tv, --th;
    }
    #scroller > div {
      z-index: -1;
      width: 50px;
      height: 50px;
    }
    #target_v {
      animation: anim 1s linear forwards;
      animation-timeline: --tv;
    }
    #target_h {
      animation: anim 1s linear forwards;
      animation-timeline: --th;
    }
  </style>
  <div id=scroller>
    <!-- Created dynamically -->
  </div>
</template>
<script>
  promise_test(async (t) => {
    inflate(t, multiple_timelines);

    // Create a 350px x 350px grid (7x7 items of 50x50px each), with the
    // timelines at item [3,3], an element attached to the horizontal timeline
    // at [4,3], and an element attached to the vertical timeline at [3,4].

    // x  x  x  x  x  x  x
    // x  x  x  x  x  x  x
    // x  x  x  x  x  x  x
    // x  x  x  T  H  x  x
    // x  x  x  V  x  x  x
    // x  x  x  x  x  x  x
    // x  x  x  x  x  x  x
    // x  x  x  x  x  x  x

    let grid_size = 7;
    for (let i = 0; i < (grid_size*grid_size); ++i) {
      let div = document.createElement('div');
      if (i == (3 * grid_size + 3))
        div.id = 'timelines';
      if (i == (3 * grid_size + 4))
        div.id = 'target_h';
      if (i == (4 * grid_size + 3))
        div.id = 'target_v';
      scroller.append(div);
    }

    assert_equals(getComputedStyle(target_v).zIndex, '-1');
    assert_equals(getComputedStyle(target_h).zIndex, '-1');

    // First scroll vertically.
    await scrollTop(scroller, 25);
    assert_equals(getComputedStyle(target_v).zIndex, '-1');
    assert_equals(getComputedStyle(target_h).zIndex, '-1');
    await scrollTop(scroller, 50); // 0% (enter 0%)
    assert_equals(getComputedStyle(target_v).zIndex, '0');
    assert_equals(getComputedStyle(target_h).zIndex, '-1');
    await scrollTop(scroller, 125); // 50%
    assert_equals(getComputedStyle(target_v).zIndex, '50');
    assert_equals(getComputedStyle(target_h).zIndex, '-1');
    await scrollTop(scroller, 200); // 100% (exit 100%)
    assert_equals(getComputedStyle(target_v).zIndex, '100');
    assert_equals(getComputedStyle(target_h).zIndex, '-1');
    document.getElementById('target_v').getAnimations()[0].
        effect.updateTiming({ fill: 'none' });
    assert_equals(getComputedStyle(target_v).zIndex, '-1');
    assert_equals(getComputedStyle(target_h).zIndex, '-1');

    // Then horizontally.
    await scrollLeft(scroller, 25);
    assert_equals(getComputedStyle(target_v).zIndex, '-1');
    assert_equals(getComputedStyle(target_h).zIndex, '-1');
    await scrollLeft(scroller, 50); // 0% (enter 0%)
    assert_equals(getComputedStyle(target_v).zIndex, '-1');
    assert_equals(getComputedStyle(target_h).zIndex, '0');
    await scrollLeft(scroller, 125); // 50%
    assert_equals(getComputedStyle(target_v).zIndex, '-1');
    assert_equals(getComputedStyle(target_h).zIndex, '50');
    await scrollLeft(scroller, 200); // 100% (exit 100%)
    assert_equals(getComputedStyle(target_v).zIndex, '-1');
    assert_equals(getComputedStyle(target_h).zIndex, '100');
    document.getElementById('target_h').getAnimations()[0].
        effect.updateTiming({ fill: 'none' });
    assert_equals(getComputedStyle(target_v).zIndex, '-1');
    assert_equals(getComputedStyle(target_h).zIndex, '-1');
  }, 'Multiple view-timelines on the same element');
</script>