css教程网 css教程网365css.cn
公告为您打开互联网世界的窗户关于本站
首页/属性速查/动画与变换

transition

属性变化时的补间动画,定义「怎么变过去」。

语法
transition: <property> <duration> <timing-function> <delay>, ...
常用值
transform .24s cubic-bezier(.2,.9,.3,1) / all .2s
初始值
all 0s ease 0s
继承
否

运行效果

示例改成别的值试试,差异一眼能看出来
查看代码
HTML
<div class="tn"><i></i></div>
CSS
.tn i { display: block; width: 70px; height: 44px; border-radius: 8px; background: #2b57ff; transition: width .4s cubic-bezier(.2,.9,.3,1), background .4s; }
.tn:hover i { width: 170px; background: #ff8a5c; }

使用要点

  • 不要用 transition: all,会连不相关的属性一起动画,造成意外抖动。
  • 进入用 ease-out,离开用 ease-in;位移越大时长越长。