transition-timing-function [过渡效果]

  1. 语法
  2. 说明
  3. 取值
  4. 实例代码
  5. 兼容性

transition-timing-function用来定义过渡动画的效果。

语法


/*设置动画执行的方式(缓动效果)。*/
transition-timing-function: linear | ease | ease-in | ease-out | ease-in-out | cubic-bezier(<number>, <number>, <number>, <number>)[ ,linear | ease | ease-in | ease-out | ease-in-out | cubic-bezier(<number>, <number>, <number>, <number>) ]* ;
语法项目 说明
初始值 ease
适用于 所有元素
可否继承
媒介 视觉
版本 CSS3.0

说明

transition-timing-function可以设置动画的过渡效果,默认值ease。

取值

ease:缓解效果,等同于cubic-bezier(0.25,0.1,0.25,1.0)函数,既立方贝塞尔。

linear:线性效果,等同于cubic-bezier(0.0,0.0,1.0,1.0)函数。

ease-in:渐显效果,等同于cubic-bezier(0.42,0,1.0,1.0)函数。

ease-out:渐隐效果,等同于cubic-bezier(0,0,0.58,1.0)函数。

ease-in-out:渐显渐隐效果,等同于cubic-bezier(0.42,0,0.58,1.0)函数。

cubic-bezier:特殊的立方贝塞尔曲线效果。

实例代码

ease
linear
ease-in
ease-out
ease-in-out
cubic-bezier(0.52,0,0.58,1.0)

<div class="demo_box ease">ease</div>
<div class="demo_box linear">linear</div>
<div class="demo_box ease-in">ease-in</div>
<div class="demo_box ease-out">ease-out</div>
<div class="demo_box ease-in-out">ease-in-out</div>
<div class="demo_box cubic-bezier">cubic-bezier(0.52,0,0.58,1.0)</div>
<button type="button" id="run" class="btn btn-sm btn-teal">运行</button>
  

.demo_box{
    -webkit-transition:all 2s 0.5s;
    -moz-transition:all 2s 0.5s;
    position:relative;
    left:10px;
    width:50px;
    height:50px;
    border-radius:50px;
    margin:10px 0;
    overflow:hidden;
}
.ease{
    -webkit-transition-timing-function:ease;
    -moz-transition-timing-function:ease;
}
.linear{
    -webkit-transition-timing-function:linear;
    -moz-transition-timing-function:linear;
}
.ease-in{
    -webkit-transition-timing-function:ease-in;
    -moz-transition-timing-function:ease-in;
}
.ease-out{
    -webkit-transition-timing-function:ease-out;
    -moz-transition-timing-function:ease-out;
}
.ease-in-out{
    -webkit-transition-timing-function:ease-in-out;
    -moz-transition-timing-function:ease-in-out;
}
.cubic-bezier{
    -webkit-transition-timing-function:cubic-bezier(0.52,0,0.58,1.0);
    -moz-transition-timing-function:cubic-bezier(0.52,0,0.58,1.0);
}
.run{
    left:500px;
}
  

$(function(){
    var i=0;
    $("#run").click(function(){
        if(i==0){
            $(".demo_box").addClass("run");
            $(this).text("返回");
            i=1;
        } else {
            $(".demo_box").removeClass("run");
            $(this).text("运行");
            i=0;
        }
    })
});
  

兼容性

IE Firefox Opera Safari Chrome
IE 10+ Firefox 3.5+ Opera 11.50+ Safari 10+ Chrome 2.0+
0 条评论