CSS3中的transition属性可以让元素发生平滑的过渡效果。而transition-timing-function属性可以控制过渡的运动方式。
transition-timing-function: linear;其中linear是匀速的运动方式,即元素沿着一条直线以恒定的速度移动。
除了linear外,CSS3中还支持ease、ease-in、ease-out、ease-in-out、step-start、step-end等不同的运动方式,可以实现更丰富的动画效果。
例如,定义一个按钮在鼠标悬停时变为红色:
button {
background-color: white;
transition: background-color 0.5s linear;
}
button:hover {
background-color: red;
} 运用linear运动方式,按钮在0.5秒内平滑地从白色变为红色。