summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/scroll-animations/view-timelines/contain-alignment.html
blob: 8b61a9ab81ca46aa2c1530e00a7332fc70bf05cb (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
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="help" src="https://drafts.csswg.org/scroll-animations-1/">
<style>

@keyframes bg {
  from { background-color:  rgb(254, 0, 0); }
  to { background-color: rgb(0 254, 0); }
}
.item {
  flex-grow: 1;
  width: 2em;
  height: 2em;
  background: #888;
  animation: bg linear;
  animation-timeline: view();
  animation-range: contain;
}

.inline .item {
  animation-timeline: view(inline);
}

.scroller {
  width: 10em;
  height: 10em;
  outline: 1px solid;
  margin: 1em;
  overflow: auto;
  display: inline-flex;
  vertical-align: top;
  flex-direction: column;
  gap: 1em;
  resize: vertical;
}

.inline {
  resize: horizontal;
  flex-direction: row;
}

.block .spacer {
  height: 20em;
  width: 1em;
}

.inline .spacer {
  width: 20em;
  height: 1em;
}
</style>
<body>
<div class="scroller block">
  <div class="item" id="a"></div>
  <div class="item" id="b"></div>
  <div class="item" id="c"></div>
</div>

<div class="scroller inline">
  <div class="item" id="d"></div>
  <div class="item" id="e"></div>
  <div class="item" id="f"></div>
</div>

<br>

<div class="scroller block">
  <div class="item" id="g"></div>
  <div class="item" id="h"></div>
</div>

<div class="scroller inline">
  <div class="item" id="i"></div>
  <div class="item" id="j"></div>
</div>
</body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
<script type="text/javascript">
  promise_test(async t => {
    let anims = document.getAnimations();
    await Promise.all(anims.map(anim => anim.ready));
    await waitForNextFrame();

    const expected_results = [
      { id: "a", progress: 1.0, bg: 'rgb(0, 254, 0)' },
      { id: "b", progress: 0.5, bg: 'rgb(127, 127, 0)' },
      { id: "c", progress: 0.0, bg: 'rgb(254, 0, 0)' },
      { id: "d", progress: 1.0, bg: 'rgb(0, 254, 0)' },
      { id: "e", progress: 0.5, bg: 'rgb(127, 127, 0)' },
      { id: "f", progress: 0.0, bg: 'rgb(254, 0, 0)' },
      { id: "g", progress: 1.0, bg: 'rgb(0, 254, 0)' },
      { id: "h", progress: 0.0, bg: 'rgb(254, 0, 0)' },
      { id: "i", progress: 1.0, bg: 'rgb(0, 254, 0)' },
      { id: "j", progress: 0.0, bg: 'rgb(254, 0, 0)' }
    ];

    expected_results.forEach(result => {
      const element = document.getElementById(result.id);
      const anim = element.getAnimations()[0];
      assert_approx_equals(anim.effect.getComputedTiming().progress,
        result.progress, 1e-3,
        `${result.id}: Unexpected progress`);
      assert_equals(getComputedStyle(element).backgroundColor,
                    result.bg, `${result.id}: Mismatched background color`);
    });

  }, 'Stability of animated elements aligned to the bounds of a contain region');
</script>
</html>