自訂動畫css屬性

來源:互聯網
上載者:User

標籤:

自訂動畫:

1.animation-name(自訂動畫名稱)

元素所應用的動畫名稱,必須與@keyframes使用,名稱由@keyframes定義。

keyframes(動畫主要畫面格):以@keyframes開頭,其中{}所寫入的是不同時間段的樣式規則。

<style type="text/css">    .div {     width: 100px;              height: 100px;              background: blue;              animation-name: lefttoright;         }    @keyframes lefttoright  {      /*定義動畫名稱為lefttoright*/
         from {margin-left:0px;}      
         to {margin-left:300px;}
      }
</style>

2.animation-duration(動畫時間)

<style type="text/css">.div {     width:100px;          height: 100px;          background:blue;          animation-name:lefttoright;                  animation-duration: 3s;                }@keyframes lefttoright {        from {margin-left: 0}        to {margin-left: 300px;}     }    

3.animation-timing-function(動畫過渡速度類型)

linear:線性過渡

ease:平滑過渡

ease-in:由慢到快

ease-out:由快到慢

ease-in-out:由慢到快再到慢

<style type="text/css">.div {     width: 100px;        height: 100px;        background: blue;        animation-name: lefttoright;        animation-timing-function:ease-out;   /*由快到慢*/    }             @keyframes lefttoright  {        from {margin-left: 0}        to {margin-left: 300px;}        }                     </style>    

4.animation-delay:(動畫延遲時間)

<style type="text/css">.div {     width: 100px;        height: 100px;        background: blue;        animation-name: lefttoright;        animation-timing-function:ease-out;        animation-delay:2s;    }        @keyframes lefttoright  {        from {margin-left: 0}        to {margin-left: 300px;}        }</style>

5.animation-iteration-count(動畫執行次數)

<style type="text/css">    .div {     width: 100px;            height: 100px;            background: blue;            animation-name: lefttoright;            animation-timing-function:ease-out;            animation-delay:2s;            animation-iteration-count:infinite;    /*無數次*/          }            @keyframes lefttoright  {            from {margin-left: 0}            to {margin-left: 300px;}         }                     </style>

6.animation-direction(動畫順序)

normal:正常方向

reverse:反方向運動

alternate:先正常運動再反方向運動,並持續交替運動

aiternate-reverse:先反方向運動再正方向,並持續交替運動

<style type="text/css">.div {     width: 100px;        height: 100px;        background: blue;        animation-name: lefttoright;        animation-timing-function:ease-out;        animation-delay:2s;        animation-iteration-count:infinite;        animation-direction:alternate;    /*動畫先正常運行再反方向運行,並持續交替運行*/     }        @keyframes lefttoright  {        from {margin-left: 0}        to {margin-left: 300px;}    }                     </style>

7. animation-play-state(動畫狀態)

<style type="text/css">.div {     width:100px;        height: 100px;        background:blue;        animation-name:lefttoright;                animation-duration: 3s;        animation-timing-function:ease-in;        animation-delay:2s;        animation-iteration-count:infinite;        animation-direction:alternate;        animation-fill-mode: forwards;    }         .div:hover { animation-play-state:paused; }    /*當滑鼠移動到div中,動畫暫停*/         @keyframes lefttoright {        from {margin-left: 0}        to {margin-left: 300px;}    }</style>

8.animation-fill-mode(動畫時間之外的狀態)

none:預設值,不設定對象動畫之外的狀態

forwards:設定對象為動畫結束時的狀態

backwards:設定對象為動畫開始時的狀態

both:設定對象為動畫開始或結束的狀態

<style type="text/css">.div {     width: 100px;        height: 100px;        background: blue;        animation-name: lefttoright;        animation-timing-function:ease-out;        animation-delay:2s;        animation-iteration-count:infinite;        animation-direction:alternate;        animation-fill-mode: forwards;    }        @keyframes lefttoright  {        from {margin-left: 0}        to {margin-left: 300px;}     }                     </style>

9.animation(動畫複合屬性)

文法:animation:[ animation-name ] || [ animation-duration ] || [ animation-timing-function ] || [ animation-delay ] || [animation-iteration-count ] || [ animation-direction ] || <single-animation-fill-mode> || <single-animation-play-state> 

<style type="text/css">.div{            width: 100px;    height: 100px;    background: blue;        animation:lefttoright 3s ease-out forwards;}    @keyframes lefttoright {    from {margin-left: 0}    to {margin-left: 300px;}}</style>    

 

自訂動畫css屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.