Logan 如果前面还有路,答应我,跑下去...

学习CSS3--CSS3过渡

2017-09-11
Logan
CSS
 

CSS3过渡

过渡(transition)

  • 允许CSS的值在一定时间区间内平滑地过渡
  • 在鼠标单击、获得焦点、被点击或对元素任何改变中触发,并圆滑地以动画效果改变CSS的属性值

兼容性

IE10+ Firefox16+ Chrome26+ Safari6.1+ Opera12.1+

transition-property

检索或设置对象中的参与过渡的属性

语法

transition-property: none | all | property;

  • none : 没有属性改变
  • all : 所有属性改变(默认)
  • property : 元素属性名
.box{
	-webkit-transition-property: transform;
	   -moz-transition-property: transform;
	    -ms-transition-property: transform;
	     -o-transition-property: transform;
	        transition-property: transform;
}

transition-duration

检索或设置对象中的参与过渡的持续时间

语法

transition-duration: time;

  • time : 规定完成过渡效果需要花费的时间(以秒或毫秒计),默认是0
.box{
	-webkit-transition-duration: 2s;
	   -moz-transition-duration: 2s;
	    -ms-transition-duration: 2s;
	     -o-transition-duration: 2s;
	        transition-duration: 2s;
}

transition-timing-function

检索或设置对象中的参与过渡的动画类型

语法

transition-timing-function: ease | linear | ease-in | ease-out | ease-in-out | cubic-bezier(n,n,n,n)

  • ease(默认) : 规定慢速开始,然后变快,然后慢速结束的过渡效果(cubic-bezier(0.25,0.1,0.25,1))
  • linear : 规定以相同速度开始至结束的过渡效果(等于 cubic-bezier(0,0,1,1))
  • ease-in : 规定以慢速开始的过渡效果(等于 cubic-bezier(0.42,0,1,1))
  • ease-out : 规定以慢速结束的过渡效果(等于 cubic-bezier(0,0,0.58,1))
  • ease-in-out : 规定以慢速开始和结束的过渡效果(等于 cubic-bezier(0.42,0,0.58,1))
  • cubic-bezier(n,n,n,n) : 在 cubic-bezier 函数中定义自己的值。可能的值是 0 至 1 之间的数值
.box{
	-webkit-transition-timing-fuction: ease-in;
	   -moz-transition-timing-fuction: ease-in;
	    -ms-transition-timing-fuction: ease-in;
	     -o-transition-timing-fuction: ease-in;
	        transition-timing-fuction: ease-in;
}

transition-delay

检索或设置对象延迟过渡的时间

语法

transition-delay: time

  • time : 规定延迟过渡效果的时间(以秒或毫秒计),默认是0
.box{
	-webkit-transition-duration: 2s;
	   -moz-transition-duration: 2s;
	    -ms-transition-duration: 2s;
	     -o-transition-duration: 2s;
	        transition-duration: 2s;
}

transition属性简写

语法

transition: property duration timing-fuction delay

.box{
	-webkit-transition: transform 2s ease-in-out 1s;
	   -moz-transition: transform 2s ease-in-out 1s;
	    -ms-transition: transform 2s ease-in-out 1s;
	     -o-transition: transform 2s ease-in-out 1s;
	        transition: transform 2s ease-in-out 1s;
}

留言

目录