企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# CSS3 animation-timing-function 属性 ## 实例 从开头到结尾以相同的速度来播放动画: ``` div { animation-timing-function:2s; -webkit-animation-timing-function:2s; /* Safari 和 Chrome */ } ``` ## 浏览器支持 | IE | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | Internet Explorer 10、Firefox 以及 Opera 支持 animation-timing-function 属性。 Safari 和 Chrome 支持替代的 -webkit-animation-timing-function 属性。 注释:Internet Explorer 9 以及更早的版本不支持 animation-timing-function 属性。 ## 定义和用法 animation-timing-function 规定动画的速度曲线。 速度曲线定义动画从一套 CSS 样式变为另一套所用的时间。 速度曲线用于使变化更为平滑。 | 默认值: | ease | | --- | --- | | 继承性: | no | | --- | --- | | 版本: | CSS3 | | --- | --- | | JavaScript 语法: | _object_.style.animationTimingFunction="linear" | | --- | --- | ## 语法 ``` animation-timing-function: _value_; ``` animation-timing-function 使用名为三次贝塞尔(Cubic Bezier)函数的数学函数,来生成速度曲线。您能够在该函数中使用自己的值,也可以预定义的值: | 值 | 描述 | 测试 | | --- | --- | --- | | linear | 动画从头到尾的速度是相同的。 | [测试](/tiy/c.asp?f=css_animation-timing-function) | | ease | 默认。动画以低速开始,然后加快,在结束前变慢。 | [测试](/tiy/c.asp?f=css_animation-timing-function&p=2) | | ease-in | 动画以低速开始。 | [测试](/tiy/c.asp?f=css_animation-timing-function&p=3) | | ease-out | 动画以低速结束。 | [测试](/tiy/c.asp?f=css_animation-timing-function&p=4) | | ease-in-out | 动画以低速开始和结束。 | [测试](/tiy/c.asp?f=css_animation-timing-function&p=5) | | cubic-bezier(_n_,_n_,_n_,_n_) | 在 cubic-bezier 函数中自己的值。可能的值是从 0 到 1 的数值。 | 提示:请试着在下面的“亲自试一试”功能中使用不同的值。 ## 亲自试一试 - 实例 ### 实例 1 为了更好地理解不同的定时函数值,这里提供了设置五个不同值的五个不同的 div 元素: ``` /* W3C 和 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 和 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;} ``` ### 实例 2 与上例相同,但是通过 cubic-bezier 函数来定义速度曲线: ``` /* W3C 和 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 和 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 动画](/css3/css3_animation.asp "CSS3 动画")