动态效果图

62 阅读1分钟

animation: myfirst 5s; 是 CSS 中的一个属性,用于设置动画的名称和持续时间。其中 myfirst 是动画的名称,5s 表示动画的持续时间为 5 秒。

动画速度曲线 animation-timing-function

动画无限次重复

animation-iteration-count: infinite;

图片动画方向为交替

animation-direction:alternate;

运行代码:

 <!DOCTYPE html>
     <html lang="en">
     <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
          *{
             margin: 30px;
          }
          div{
             width: 100px;
             height: 100px;
            background: bisque;
             position: relative;
             animation: myfirst 5s; 
             animation-timing-function:ease;  /*动画速度曲线为ease */
             animation-iteration-count: infinite;  /*动画无限次重复*/
              animation-direction:alternate;      /*图片动画方向为交替*/  
          }

          @keyframes myfirst{
             0%{background: bisque;left:0px; top:0px;}
             25%{background: chocolate;left:200px; top:0px;}
             50%{background: darkgray;left:200px; top:200px;}
             75%{background: darkblue;left:0px; top:200px;}
             100%{background: black;left:0px; top:0px;}
          }
        </style>
     </head>
     <body>
       <div>你好!</div>
     </body>
     </html>