summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/scroll-animations/css/view-timeline-with-transform-on-subject.html
blob: e4abac7219be6392e98ffb6ec4118ec18c0450cf (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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="help" src="https://drafts.csswg.org/scroll-animations-1/#named-timeline-range">
<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>
<title>Animation range and delay</title>
</head>
<style type="text/css">
  @keyframes anim {
    from { transform: scaleX(0) translateY(0); }
    to { transform: scaleX(1) translatey(50vh); }
  }
  #scroller {
    border:  10px solid lightgray;
    overflow-y: scroll;
    overflow-x: hidden;
    width: 300px;
    height: 200px;
  }
  .spacer {
    height: 200px;
  }
  #target {
    height: 50px;
    background-color: green;
    animation: anim auto both linear;
    animation-timeline: view();
    animation-range-start: contain 0%;
    animation-range-end: contain 100%;
  }
</style>
<body>
  <div id=scroller>
    <div class="spacer"></div>
    <div id="target"></div>
    <div class="spacer"></div>
  </div>
</body>
<script type="text/javascript">
  async function runTest() {
    function assert_progress_equals(anim, expected, errorMessage) {
      assert_approx_equals(
          anim.effect.getComputedTiming().progress,
          expected, 1e-6, errorMessage);
    }

    promise_test(async t => {
      await waitForNextFrame();
      const anim = document.getAnimations()[0];
      await anim.ready;
      await waitForNextFrame();

      // @ contain 0%
      scroller.scrollTop = 50;
      await waitForNextFrame();
      assert_progress_equals(anim, 0, 'progress at contain 0%');

      // @ contain 50%
      scroller.scrollTop = 125;
      await waitForNextFrame();
      assert_progress_equals(anim, 0.5, 'progress at contain 50%');

      // @ contain 100%
      scroller.scrollTop = 200;
      await waitForNextFrame();
      assert_progress_equals(anim, 1, 'progress at contain 100%');
    }, 'ViewTimeline use untransformed box for range calculations');
  }

  window.onload = runTest;
</script>
</html>