哪个 CSS 属性可用于以交替循环的方式运行动画?

cssweb developmentfront end technology更新于 2024/7/12 4:28:17

使用 animation-direction 属性可按交替方向运行动画。该属性与 alternate animation 值配合使用可实现此目的。

示例

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            width: 150px;
            height: 200px;
            background-color: yellow;
            animation-name: myanim;
            animation-duration: 2s;
            animation-direction: alternate;
            animation-iteration-count: 3;
         }
         @keyframes myanim {
            from {
               background-color: green;
            }
            to {
               background-color: blue;
            }
         }
      </style>
   </head>
   <body>
      <div></div>
   </body>
</html>

相关文章


有用资源