tor-browser

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

animation-with-transform.html (1646B)


      1 <html class="reftest-wait">
      2 <title>Basic use of scroll timeline with Web Animation</title>
      3 <link rel="help" href="https://drafts.csswg.org/scroll-animations/">
      4 <meta name="assert" content="Should be able to use the scroll timeline to drive the animation timing">
      5 <link rel="match" href="animation-ref.html">
      6 
      7 <script src="/web-animations/testcommon.js"></script>
      8 <script src="/common/reftest-wait.js"></script>
      9 
     10 <style>
     11  #box {
     12    width: 100px;
     13    height: 100px;
     14    background-color: green;
     15  }
     16 
     17  #covered {
     18    width: 100px;
     19    height: 100px;
     20    background-color: red;
     21  }
     22 
     23  #scroller {
     24    overflow: hidden;
     25    height: 100px;
     26    width: 100px;
     27    will-change: transform; /* force compositing */
     28  }
     29 
     30  #contents {
     31    height: 1000px;
     32    width: 100%;
     33  }
     34 </style>
     35 
     36 <div id="box"></div>
     37 <div id="covered"></div>
     38 <div id="scroller">
     39  <div id="contents"><p>Scrolling Contents</p></div>
     40 </div>
     41 
     42 <script>
     43  const box = document.getElementById('box');
     44  const effect = new KeyframeEffect(box,
     45    [
     46    { transform: 'translateY(0)', opacity: 1},
     47    { transform: 'translateY(200px)', opacity: 0}
     48    ], {
     49      duration: 1000,
     50    }
     51  );
     52 
     53  const scroller = document.getElementById('scroller');
     54  const timeline = new ScrollTimeline(
     55      { source: scroller, orientation: 'block' });
     56  const animation = new Animation(effect, timeline);
     57  animation.play();
     58 
     59  animation.ready.then(() => {
     60    // Move the scroller to the halfway point.
     61    const maxScroll = scroller.scrollHeight - scroller.clientHeight;
     62    scroller.scrollTop = 0.5 * maxScroll;
     63 
     64    waitForAnimationFrames(2).then(_ => {
     65      takeScreenshot();
     66    });
     67  });
     68 </script>