使用 CSS 设置从开始到结束速度相同的动画

cssweb developmentfront end technology更新于 2024/7/20 3:56:17

使用 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>

相关文章


有用资源