CSS3中Transitions属性的使用方法 1

在CSS 3中,Transitions功能通过将元素的某个属性从一个属性值在指定时间内平滑过渡到另一个属性值来实现动画功能。可通过transtions属性来使用Transtions功能。

transtions属性的使用方法如下所示:

transtion:property duration timing-function

其中property表示属性进行平滑过渡,duraton表示在多长时间内完成属性值的平滑过渡,tinming-function表示通过什么方法来进行平滑过渡。

div { width:120px; height:90px; background:blue; transition:background-color 2s linear; }
div:hover { background:orange; }

上面的实例中,把div元素的蓝色背景在2秒钟之内平滑过渡到橙色背景。

当然还有另外一种使用Transitions功能的方法,就是将Transitions属性中的参数分开来写,例如下面的代码:

transtion-property:backgroud-color; transtion-duration:1s; tarnstion-timing-function:linear;

使用Transitions功能同时对于多个属性值进行平滑过渡:

div { width:120px; height:90px; background:blue; -moz-transition:background-color 1s linear,height 1s linear; }
div:hover { height:240px; background:orange; }

上面的实例中,元素从背景为蓝色、高度为120像素平滑过渡到背景为橙色,高度为240像素。

使用Transitions功能实现元素的移动与旋转动画:

img { position:absolute; top:270px; left:10px; -moz-transform:rotate(0deg); -moz-transition:left 5s linear,-moz-transform 1s linear; }
img:hover { left:230px; -moz-transform:rotate(15deg); }

上面的实例中,使定位图片元素从距左边距10像素、旋转角度为0状态平滑过渡到距左边距230像素、旋转15度。

声明:本站所有文章均摘自网络。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。