transition也可实现动画。transition强调过渡,是元素的一个或多个属性发生变化时产生的过渡效果,同一个元素通过两个不同的途径获取样式,而第二个途径当某种改变发生(如hover)时才能获取样式,这样就会产生过渡动画。
其实css3有两种方式实现这个效果:
1. css3 过度transition
.class{position:relative
-webkit-transition: top 10s linear /*top 时间(用秒计算)s linear*/
-moz-transition: top 10s linear
-o-transition: top 10s linear
transition: top 10s linear
}
.class:hover{
top:100px
}
详见:http://www.w3school.com.cn/css3/css3_transition.asp
2. css3 动画animation
@-webkit-keyframes myfirst{from {top: 0}
to {top: 100px}
}
@-moz-keyframes myfirst{
from {top: 0}
to {top: 100px}
}
@-o-keyframes myfirst{
from {top: 0}
to {top: 100px}
}
@keyframes myfirst{
from {top: 0}
to {top: 100px}
}
.class{
position:relative
}
.class:hover{
-webkit-animation:myfirst 10s
-moz-animation:myfirst 10s
-o-animation:myfirst 10s
animation:myfirst 10s
}
详见:http://www.w3school.com.cn/css3/css3_animation.asp
要得上面的线性渐变效果,我们这样去定义CSS3样式:background-image: -moz-linear-gradient(top, #8fa1ff, #3757fa)/* Firefox */background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #ff4f02), color-stop(1,...