css---动画封装

animation-name

属性指定应用的一系列动画,每个名称代表一个由@keyframes定义的动画序列

值:
none
特殊关键字,表示无关键帧。
keyframename
标识动画的字符串

animation-nanme:move;

animation-duration属性指定一个动画周期的时长。
默认值为0s,表示无动画。


一个动画周期的时长,单位为秒(s)或者毫秒(ms),无单位值无效。
注意:负值无效,浏览器会忽略该声明,但是一些早起的带前缀的声明会将负值当作0s

 animation-duration: 3s;

animation-timing-function属性定义CSS动画在每一动画周期中执行的节奏。
对于关键帧动画来说,timing function作用于一个关键帧周期而非整个动画周期,即从关键帧开始,到关键帧结束。

动画的默认效果:由慢变快再变慢

linear:线性过渡,等同于贝塞尔曲线(0,0,1,1)
ease:平滑过渡,等同于贝塞尔曲线(0.25,0.1,0.25,1.0)
ease-in:由慢到快,等同于贝塞尔曲线(0.42,0,1,1)
ease-out:由快到慢,等同于贝塞尔曲线(0,0,0.58,1)
ease-in-out:由慢到快再到慢,等同于贝塞尔曲线(0.42,0,0.58,1)
cubic-bezier(1,1,2,3)

  /*           运动线性*/
             animation-timing-function:linear;

steps(n,[start|end])
传入一到两个参数,第一个参数意思是把动画分成 n 等分,然后动画就会平均地运行。
第二个参数 start 表示从动画的开头开始运行,相反,end 就表示从动画的结尾开始运行,
默认值为 end。

animation-delay:3s定义动画开始前等待的时间,以秒或毫秒计(属于动画外的范畴)

值:
<time>
从动画样式应用到元素上到元素开始执行动画的时间差。该值可用单位为秒(s)和毫秒(m s)。如果未设置单位,定义无效

           /*  运动缓存时间*/
             animation-delay: 3s;

  animation-iteration-count: infinite;

定义了动画执行的次数(属于动画内的范畴)


infinite
无限循环播放动画.
<number>
动画播放的次数 不可为负值.

animation-direction:

定义了动画执行的方向


normal
每个循环内动画向前循环,换言之,每个动画循环结束,动画重置到起点重新开始, 这是默认属性。
alternate
动画交替反向运行,反向运行时,动画按步后退,同时,带时间功能的函数也反向, 比如,ease-in 在反向时成为ease-out。计数取决于开始时是奇数迭代还是偶数迭 代
reverse
反向运行动画,每周期结束动画由尾到头运行。
alternate-reverse
反向交替, 反向开始交替

              /* 运动方向*/
               animation-direction:reverse;
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
          *{
               margin: 0;
               padding: 0;
          }
          #wrap{
              position: relative;
            margin: 200px auto;
               300px;
              height: 300px;
              border: 1px solid;
          }
          #test{
              position:absolute;
              left:50%;
              top: 50%;
          /*    transform: translate3d(-50%,-50%,0);*/
            margin-left: -50px;
            margin-top: -50px;
               100px;
              height: 100px;
              background: red;
            border-radius:50%;
          /*  定义动画名称*/
            animation-name:move;
            text-align: center;
             line-height: 100px;
             /*定义动画运动到结束时间*/
             animation-duration: 8s;
  /*           运动线性*/
             animation-timing-function:linear;
           /*  运动缓存时间*/
             animation-delay: 3s;
             
             /*动画内的属性*/
            /* 运动次数*/
             animation-iteration-count: infinite;
              }
              /* 运动方向*/
               animation-direction:reverse;
              @keyframes move{
                  from{transform:rotate(0deg);}
                  to{transform:rotate(360deg);}
              }
            
        </style>
    </head>
    <body>
        <div id="wrap">
            <div id="test">0000</div>
        </div>
    </body>
</html>
View Code

animation-fill-mode:forwards;

* backwards:from之前的状态与form的状态保持一致
* forwards:to之后的状态与to的状态保持一致
* both:backwards+forwards

    animation-fill-mode: both;
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            
            *{
                margin: 0;
                padding: 0;
            }
            
            #wrap{
                position: relative;
                margin: 200px auto;
                 300px;
                height: 300px;
                border: 1px solid;
            }
            #test{
                position: absolute;
                left: 50%;
                top: 50%;
                /*transform: translate3d(-50%,-50%,0);*/
                margin-left:-50px;
                margin-top: -50px;
                 100px;
                height: 100px;
                background: pink;
                text-align: center;
                font: 20px/100px "微软雅黑";
                
                /*动画内的属性*/
                animation-name: move;
                animation-duration:3s ;
                animation-timing-function: linear;
                    /*反转的是关键帧和animation-timing-function*/
                animation-direction:normal;
                /*动画外的属性*/
                animation-delay:1s;
                
                /*只作用于动画内的属性*/
                    /*重复的是关键帧*/
                animation-iteration-count: 3;
                
                
                /*元素在动画外的状态
                 
                 * 
                 * backwards:from之前的状态与form的状态保持一致
                 * forwards:to之后的状态与to的状态保持一致
                 * both:backwards+forwards
                 * */
                    
                animation-fill-mode: both;
                animation-play-state: running;
            }
            
            @keyframes move{
                from{
                    transform: translateY(-100px);
                }
                to{
                    transform: translateY(100px);
                }
            }
            
            #wrap:hover #test{
                animation-play-state: paused;
            }
        </style>
    </head>
    <body>
        <div id="wrap">
            <div id="test">邱海峰</div>
        </div>
    </body>
</html>
View Code
原文地址:https://www.cnblogs.com/hack-ing/p/11785820.html