用 CSS 设置一个从头到尾速度相同的动画


使用 animation-timing-function 属性,带有 linear 值,从而用 CSS 设置从头到尾速度相同的动画

范例

实时演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            width: 150px;
            height: 200px;
            position: relative;
            background-color: yellow;
            animation-name: myanim;
            animation-duration: 2s;
            animation-direction: alternate-reverse;
            animation-iteration-count: 3;
         }
         @keyframes myanim {
            from {left: 100px;}
            to {left: 200px;}
         }
         #demo {animation-timing-function: linear;}
      </style>
   </head>
   <body>
      <div id = "demo">linear effect</div>
   </body>
</html>

更新于:24-6-2020

221 查看

开启您的职业

完成课程获得证书

开始学习
广告
© . All rights reserved.