tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

view-timeline-keyframe-boundary-interpolation.html (4256B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      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 <title>Animation range and delay</title>
     11 </head>
     12 <style type="text/css">
     13  @keyframes anim {
     14    cover 0% { /* resolves to -100% */
     15      opacity: 0;
     16      transform: none;
     17      margin-left:  0px;
     18      /* missing margin-right -- requires neutral keyframe at 0% */
     19    }
     20    cover 100% { /* resolves to 200% */
     21      opacity: 1;
     22      transform: translateX(300px);
     23      margin-right: 0px;
     24      /* missing margin-left -- requires neutral keyframe at 100% */
     25    }
     26  }
     27  #scroller {
     28    border:  10px solid lightgray;
     29    overflow-y: scroll;
     30    overflow-x: hidden;
     31    width: 300px;
     32    height: 200px;
     33  }
     34  #target {
     35    margin: 800px 10px;
     36    width: 100px;
     37    height: 100px;
     38    z-index: -1;
     39    background-color: green;
     40    animation:  anim auto both linear;
     41    animation-timeline: --t1;
     42    animation-range-start:  contain 0%;
     43    animation-range-end:  contain 100%;
     44    view-timeline:  --t1 block;
     45  }
     46 </style>
     47 <body>
     48  <div id=scroller>
     49    <div id=target></div>
     50  </div>
     51 </body>
     52 <script type="text/javascript">
     53  async function runTest() {
     54 
     55    const epsilon = 1e-5;
     56 
     57    function assert_progress_equals(anim, expected, errorMessage) {
     58      assert_approx_equals(
     59          anim.effect.getComputedTiming().progress,
     60          expected, epsilon, errorMessage);
     61    }
     62 
     63    function assert_opacity_equals(expected, errorMessage) {
     64      assert_approx_equals(
     65          parseFloat(getComputedStyle(target).opacity), expected, epsilon,
     66                     errorMessage);
     67    }
     68 
     69    function assert_translate_x_equals(expected, errorMessage) {
     70      const style = getComputedStyle(target).transform;
     71      const regex = /matrix\(([^\)]*)\)/;
     72      const captureGroupIndex = 1;
     73      const translateIndex = 4;
     74      const match = style.match(regex)[captureGroupIndex];
     75      const translateX = parseFloat(match.split(',')[translateIndex].trim());
     76      assert_approx_equals(translateX, expected, epsilon, errorMessage);
     77    }
     78 
     79    function assert_property_equals(property, expected, errorMessage) {
     80      const value = parseFloat(getComputedStyle(target)[property]);
     81      assert_approx_equals(value, expected, epsilon, errorMessage);
     82    }
     83 
     84    promise_test(async t => {
     85      await waitForNextFrame();
     86      const anims = document.getAnimations();
     87      assert_equals(anims.length, 1,
     88                    "Should have one animation attatched to the view-timeline");
     89      const anim = anims[0];
     90      await anim.ready;
     91      await waitForNextFrame();
     92 
     93      // @ contain 0%
     94      scroller.scrollTop = 700;
     95      await waitForNextFrame();
     96      assert_progress_equals(anim, 0, 'progress at contain 0%');
     97      assert_translate_x_equals(100, 'translation at contain 0%');
     98      assert_opacity_equals(1/3, 'opacity at contain 0%');
     99      assert_property_equals('margin-left', 5, 'margin-left at contain 0%');
    100      assert_property_equals('margin-right', 10, 'margin-right at contain 0%');
    101 
    102      // @ contain 50%
    103      scroller.scrollTop = 750;
    104      await waitForNextFrame();
    105      assert_progress_equals(anim, 0.5, 'progress at contain 50%');
    106      assert_translate_x_equals(150, 'translation at contain 50%');
    107      assert_opacity_equals(0.5, 'opacity at contain 50%');
    108      assert_property_equals('margin-left', 7.5, 'margin-left at contain 50%');
    109      assert_property_equals('margin-right', 7.5, 'margin-right at contain 50%');
    110 
    111      // @ contain 100%
    112      scroller.scrollTop = 800;
    113      await waitForNextFrame();
    114      assert_progress_equals(anim, 1, 'progress at contain 100%');
    115      assert_translate_x_equals(200, 'translation at contain 100%');
    116      assert_opacity_equals(2/3, 'opacity at contain 100%');
    117      assert_property_equals('margin-left', 10, 'margin-left at contain 100%');
    118      assert_property_equals('margin-right', 5, 'margin-right at contain 100%');
    119    }, 'ViewTimeline with timeline offset keyframes outside [0,1]');
    120  }
    121 
    122  window.onload = runTest;
    123 </script>
    124 </html>