實(shí)例
以相同的速度從開始到結(jié)束的過渡效果:
div { transition-timing-function: linear; -moz-transition-timing-function: linear; /* Firefox 4 */ -webkit-transition-timing-function: linear; /* Safari 和 Chrome */ -o-transition-timing-function: linear; /* Opera */ }
瀏覽器支持
IE | Firefox | Chrome | Safari | Opera |
---|---|---|---|---|
Internet Explorer 10、Firefox、Opera 和 Chrome 支持 transition-timing-function 屬性。
Safari 支持替代的 -webkit-transition-timing-function 屬性。
注釋:Internet Explorer 9 以及更早版本的瀏覽器不支持 transition-timing-function 屬性。
定義和用法
transition-timing-function 屬性規(guī)定過渡效果的速度曲線。
該屬性允許過渡效果隨著時間來改變其速度。
默認(rèn)值: | ease |
---|---|
繼承性: | no |
版本: | CSS3 |
JavaScript 語法: | object.style.transitionTimingFunction="linear" |
語法
transition-timing-function: linear|ease|ease-in|ease-out|ease-in-out|cubic-
bezier(n,n,n,n);
值 | 描述 |
---|---|
linear | 規(guī)定以相同速度開始至結(jié)束的過渡效果(等于 cubic-bezier(0,0,1,1))。 |
ease | 規(guī)定慢速開始,然后變快,然后慢速結(jié)束的過渡效果(cubic-bezier(0.25,0.1,0.25,1))。 |
ease-in | 規(guī)定以慢速開始的過渡效果(等于 cubic-bezier(0.42,0,1,1))。 |
ease-out | 規(guī)定以慢速結(jié)束的過渡效果(等于 cubic-bezier(0,0,0.58,1))。 |
ease-in-out | 規(guī)定以慢速開始和結(jié)束的過渡效果(等于 cubic-bezier(0.42,0,0.58,1))。 |
cubic-bezier(n,n,n,n) | 在 cubic-bezier 函數(shù)中定義自己的值??赡艿闹凳?0 至 1 之間的數(shù)值。 |
提示:請?jiān)趯?shí)例中測試不同的值,這樣可以更好地理解它們的工作原理。
親自試一試 - 實(shí)例
實(shí)例 1
為了更好地理解不同的函數(shù)值,請看下面帶有五個不同值的五個不同的 div 元素:
#div1 {transition-timing-function: linear;} #div2 {transition-timing-function: ease;} #div3 {transition-timing-function: ease-in;} #div4 {transition-timing-function: ease-out;} #div5 {transition-timing-function: ease-in-out;} /* Firefox 4: */ #div1 {-moz-transition-timing-function: linear;} #div2 {-moz-transition-timing-function: ease;} #div3 {-moz-transition-timing-function: ease-in;} #div4 {-moz-transition-timing-function: ease-out;} #div5 {-moz-transition-timing-function: ease-in-out;} /* Safari and Chrome: */ #div1 {-webkit-transition-timing-function: linear;} #div2 {-webkit-transition-timing-function: ease;} #div3 {-webkit-transition-timing-function: ease-in;} #div4 {-webkit-transition-timing-function: ease-out;} #div5 {-webkit-transition-timing-function: ease-in-out;} /* Opera: */ #div1 {-o-transition-timing-function: linear;} #div2 {-o-transition-timing-function: ease;} #div3 {-o-transition-timing-function: ease-in;} #div4 {-o-transition-timing-function: ease-out;} #div5 {-o-transition-timing-function: ease-in-out;}
實(shí)例 2
與上例相同,但通過 cubic-bezier 來規(guī)定速度曲線:
#div1 {transition-timing-function: cubic-bezier(0,0,1,1;} #div2 {transition-timing-function: cubic-bezier(0.25,0.1,0.25,1);} #div3 {transition-timing-function: cubic-bezier(0.42,0,1,1);} #div4 {transition-timing-function: cubic-bezier(0,0,0.58,1);} #div5 {transition-timing-function: cubic-bezier(0.42,0,0.58,1);} /* Firefox 4: */ #div1 {-moz-transition-timing-function: cubic-bezier(0,0,0.25,1);} #div2 {-moz-transition-timing-function: cubic-bezier(0.25,0.1,0.25,1);} #div3 {-moz-transition-timing-function: cubic-bezier(0.42,0,1,1);} #div4 {-moz-transition-timing-function: cubic-bezier(0,0,0.58,1);} #div5 {-moz-transition-timing-function: cubic-bezier(0.42,0,0.58,1);} /* Safari and Chrome: */ #div1 {-webkit-transition-timing-function: cubic-bezier(0,0,1,1;} #div2 {-webkit-transition-timing-function: cubic-bezier(0.25,0.1,0.25,1);} #div3 {-webkit-transition-timing-function: cubic-bezier(0.42,0,1,1);} #div4 {-webkit-transition-timing-function: cubic-bezier(0,0,0.58,1);} #div5 {-webkit-transition-timing-function: cubic-bezier(0.42,0,0.58,1);} /* Opera: */ #div1 {-o-transition-timing-function: cubic-bezier(0,0,1,1;} #div2 {-o-transition-timing-function: cubic-bezier(0.25,0.1,0.25,1);} #div3 {-o-transition-timing-function: cubic-bezier(0.42,0,1,1);} #div4 {-o-transition-timing-function: cubic-bezier(0,0,0.58,1);} #div5 {-o-transition-timing-function: cubic-bezier(0.42,0,0.58,1);}
更多建議: