zoukankan      html  css  js  c++  java
  • Web animation API improvements in Chromium 84

    基础概念:把 CSS 换成 JS

    @keyframes openAnimation {
      0% {
        transform: scale(0);
      }
      100% {
        transform: scale(1);
      }
    }
    
    换成
    
    const openAnimation = [
      { transform: 'scale(0)' },
      { transform: 'scale(1)' },
    ];
    .modal {
      animation: openAnimation 1s 1 ease-in;
    }
    
    换成
    
    document.querySelector('.modal').animate(
        openAnimation, {
          duration: 1000, // 1s
          iterations: 1, // single iteration
          easing: 'ease-in' // easing function
        }
    );

    新的功能

    1. 能监听 animation.ready 和 animation.finished

    2. New transitions can be triggered while existing ones are still running.

    可以在现有转换仍在运行时触发新转换。这个好!要自己实现会很复杂

    3. 可替换动画的性能改进

    elem.addEventListener('mousemove', evt => {
     rectangle.animate(
       { transform: translate(${evt.clientX}px, ${evt.clientY}px) },
       { duration: 500, fill: 'forwards' }
     );
    });

    例子中,mousemove 会触发非常多次,而最新的 animation 会被优化。

    如果自己实现,会需要 requestAnimation 来控制。

    4. 其他功能
    animation.replaceState(), animation.commitStyles(), animation.persist()

    5. composite mode

    有 3 种模式: replace, add, accumulate

    大概是说如果有多个 animation 要混着用,你可以选择不同的模式去执行。

    Link

  • 相关阅读:
    bootstrap 在页面的引入使用
    flex布局/弹性盒子
    @keyframes css3动画
    css3 圆角,阴影,渐变...
    css3 的转换和过渡
    学习正则表达式
    页面联系我们加入地图map
    @font-face的使用
    React Native组件之ScrollView 和 StatusBar和TabBarIos
    React Native组件之Switch和Picker和Slide
  • 原文地址:https://www.cnblogs.com/stooges/p/15323807.html
Copyright © 2011-2022 走看看