標籤:
動畫名稱
文法:animation-name:none|<identifier>
元素所定義的動畫名稱,必須與規則@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:<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: <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: 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: 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: 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-name ] || [ animation-duration ] || [ animation-timing-function ] || [ animation-delay ] || [animation-iteration-count ] || [ animation-direction ] || <single-animation-fill-mode> || <single-animation-play-state> [ ,*]
CSS(五):動畫