CSS3 animation-timing-function 屬性
瀏覽器支持
屬性 | |||||
---|---|---|---|---|---|
animation-timing-function | 43.0 4.0 -webkit- | 10.0 | 16.0 5.0 -moz- | 9.0 4.0 -webkit- | 30.0 15.0 -webkit- 12.0 -o- |
標簽定義及使用說明
animation-timing-function指定動畫將如何完成一個周期。
速度曲線定義動畫從一套 CSS 樣式變?yōu)榱硪惶姿玫臅r間。
速度曲線用于使變化更為平滑。
默認值: | ease |
---|---|
繼承: | no |
版本: | CSS3 |
JavaScript 語法: | objectobject.style.animationTimingFunction="linear" |
語法
animation-timing-function:value;
animation-timing-function使用的數學函數,稱為三次貝塞爾曲線,速度曲線。使用此函數,您可以使用您自己的值,或使用預先定義的值之一:
值 | 描述 |
---|---|
linear | 動畫從頭到尾的速度是相同的。 |
ease | 默認。動畫以低速開始,然后加快,在結束前變慢。 |
ease-in | 動畫以低速開始。 |
ease-out | 動畫以低速結束。 |
ease-in-out | 動畫以低速開始和結束。 |
cubic-bezier(n,n,n,n) | 在 cubic-bezier 函數中自己的值。可能的值是從 0 到 1 的數值。 |
提示:請試著在下面的"嘗試一下"功能中使用不同的值。
在線實例
實例
從開始到結束以相同的速度播放動畫:
animation-timing-function:linear;
-webkit-animation-timing-function:linear; /* Safari and Chrome */
實例
為了更好地理解不同的定時函數值,這里提供了設置五個不同值的五個不同的 div 元素:
/* W3C and Opera: */
#div1 {animation-timing-function: linear;}
#div2 {animation-timing-function: ease;}
#div3 {animation-timing-function: ease-in;}
#div4 {animation-timing-function: ease-out;}
#div5 {animation-timing-function: ease-in-out;}
/* Firefox: */
#div1 {-moz-animation-timing-function: linear;}
#div2 {-moz-animation-timing-function: ease;}
#div3 {-moz-animation-timing-function: ease-in;}
#div4 {-moz-animation-timing-function: ease-out;}
#div5 {-moz-animation-timing-function: ease-in-out;}
/* Safari and Chrome: */
#div1 {-webkit-animation-timing-function: linear;}
#div2 {-webkit-animation-timing-function: ease;}
#div3 {-webkit-animation-timing-function: ease-in;}
#div4 {-webkit-animation-timing-function: ease-out;}
#div5 {-webkit-animation-timing-function: ease-in-out;}
實例
與上例相同,但是通過 cubic-bezier 函數來定義速度曲線:
/* W3C and Opera: */
#div1 {animation-timing-function: cubic-bezier(0,0,1,1;}
#div2 {animation-timing-function: cubic-bezier(0.25,0.1,0.25,1);}
#div3 {animation-timing-function: cubic-bezier(0.42,0,1,1);}
#div4 {animation-timing-function: cubic-bezier(0,0,0.58,1);}
#div5 {animation-timing-function: cubic-bezier(0.42,0,0.58,1);}
/* Firefox: */
#div1 {-moz-animation-timing-function: cubic-bezier(0,0,1,1;}
#div2 {-moz-animation-timing-function: cubic-bezier(0.25,0.1,0.25,1);}
#div3 {-moz-animation-timing-function: cubic-bezier(0.42,0,1,1);}
#div4 {-moz-animation-timing-function: cubic-bezier(0,0,0.58,1);}
#div5 {-moz-animation-timing-function: cubic-bezier(0.42,0,0.58,1);}
/* Safari and Chrome: */
#div1 {-webkit-animation-timing-function: cubic-bezier(0,0,1,1;}
#div2 {-webkit-animation-timing-function: cubic-bezier(0.25,0.1,0.25,1);}
#div3 {-webkit-animation-timing-function: cubic-bezier(0.42,0,1,1);}
#div4 {-webkit-animation-timing-function: cubic-bezier(0,0,0.58,1);}
#div5 {-webkit-animation-timing-function: cubic-bezier(0.42,0,0.58,1);}
相關文章
CSS3 教程: CSS3 動畫