CSS(五):動畫

來源:互聯網
上載者:User

標籤:

  • animation-name

動畫名稱
文法:animation-name:none|<identifier>
元素所定義的動畫名稱,必須與規則@keyframes配合使用,因為動畫名稱由@keyframes定義。

 

  • @keyframes

文法:
@keyframes <identifier>{
[from|to|<percentage>]{sRules}[,*]
}
被稱為主要畫面格,其類似於Flash中的主要畫面格。在CSS3中其主要以“@keyframes”開頭,後面緊跟著是動畫名稱加上一對花括弧“{…}”,括弧中就是一些不同時間段樣式規則。

1 /*定義一個名為"fromLeftToRight"的向右移動的動畫*/2 @keyframes fromLeftToRight{3     from{margin:0;}4     to{margin:100px;}5 }
  • animation-duration

設定動畫的期間
文法:animation-duration:<time>[,<time>]*

1 /*給div一個名為"fromLeftToRight"的動畫效果,並持續一秒時間*/2 div{3     animation-name:fromLeftToRight;4     animation-duration:1s;5 }
  • animation-timing-function

動畫的過渡速度類型
文法:animation-timing-function:ease|linear|ease-in|ease-out|ease-in-out

1 /*給div一個名為"fromLeftToRight"的動畫效果,持續一秒時間,並且過渡類型為ease-in*/2 div{3     animation-name:fromLeftToRight;4     animation-duration:1s;5     animation-timing-function:ease-in;6 }
  • animation-delay

設定動畫的延遲時間
文法:animation-delay: <time>[,<time>]*

1 /*給div一個名為"fromLeftToRight"的動畫效果,延遲一秒後執行*/2 div{3     animation-name:fromLeftToRight;4     animation-duration:1s;5     animation-timing-function:ease-in;6     animation-delay: 1s;7 }
  • animation-iteration-count

設定動畫的執行次數
文法:animation-iteration-count: infinite|<number>
infinite表示無限次數

1 /*給div一個名為"fromLeftToRight"的動畫效果,執行兩次後停止*/2 div{3     animation-name:fromLeftToRight;4     animation-duration:1s;5     animation-timing-function:ease-in;6     animation-iteration-count: 2;7 }
  • animation-direction

設定動畫在迴圈中是否按照相反順序執行
文法:animation-direction: normal|reverse|alternate|alternate-reverse
說明:
normal:正常方向
reverse:反方向運行
alternate:動畫先正常運行再反方向運行,並持續交替運行
alternate-reverse:動畫先反運行再正方向運行,並持續交替運行

1 /*給div一個名為"fromLeftToRight"的動畫效果,並且反覆運行*/2 div{3     animation-name:fromLeftToRight;4     animation-duration:1s;5     animation-timing-function:ease-in;6     animation-iteration-count: infinite;7     animation-direction: alternate;8 }
  • animation-fill-mode

設定動畫開始結束的狀態
文法:animation-fill-mode: none|forwards|backwards|both
說明:
none:預設值。不設定動畫的狀態
forwards:設定對象狀態為動畫結束時的狀態
backwards:設定對象狀態為動畫開始時的狀態
both:設定對象狀態為動畫結束或開始的狀態

1 /*給div一個名為"fromLeftToRight"的動畫效果,並且動畫結束後元素位於動畫結束時的位置*/2 div{3     animation-name:fromLeftToRight;4     animation-duration:1s;5     animation-timing-function:ease-in;6     animation-iteration-count: 3;7     animation-fill-mode: forwards;8 }
  • animation-play-state

設定動畫的播放狀態
文法:animation-play-state: running|paused

 1 /*給div一個名為"fromLeftToRight"的動畫效果,並且當div處於hover狀態時暫停動畫*/ 2 div{ 3     animation-name:fromLeftToRight; 4     animation-duration:1s; 5     animation-timing-function:ease-in; 6     animation-iteration-count: infinite; 7 } 8 div:hover{ 9     animation-play-state: paused;10 }
  • animation

動畫的簡寫屬性
文法:
animation:[ animation-name ] || [ animation-duration ] || [ animation-timing-function ] || [ animation-delay ] || [animation-iteration-count ] || [ animation-direction ] || <single-animation-fill-mode> || <single-animation-play-state> [ ,*]

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.