CSS3 animation 属性
说明
The animation CSS property is a shorthand property for animation-name, animation-duration, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, animation-fill-mode and animation-play-state.
下表总结了此属性的使用上下文和版本历史记录。
| 默认值: | |
|---|---|
| 适用于: | 所有元素,::before 和 ::after 伪元素 |
| 继承: | No |
| 动画: | No. 参见动画属性。 |
| 版本: | New in CSS3 |
语法
属性的语法如下:
下面的示例显示了 animation 属性的作用。
.box {
width: 50px;
height: 50px;
background: red;
position: relative;
/* Chrome, Safari, Opera */
-webkit-animation: moveit 2s linear 0s infinite alternate;
/* 标准语法 */
animation: moveit 2s linear 0s infinite alternate;
}
/* Chrome, Safari, Opera */
@-webkit-keyframes moveit {
from {left: 0;}
to {left: 50%;}
}
/* 标准语法 */
@keyframes moveit {
from {left: 0;}
to {left: 50%;}
}
注意:您必须至少指定两个属性animation-name 和animation-duration(大于0),才能使动画发生。
属性值
下表描述了该属性的值。
| 值 | 说明 |
|---|---|
animation-name |
指定应应用于所选元素的 @keyframes 定义的动画的名称。 |
animation-duration |
指定动画完成一个动画周期所需的秒数或毫秒数。 |
animation-timing-function |
指定动画将如何在每个周期的持续时间内进行,即缓动函数。 |
animation-delay |
指定动画开始之前的延迟。 |
animation-iteration-count |
指定动画循环在停止之前应播放的次数。 |
animation-direction |
指定动画是否应在交替循环中反向播放。 |
animation-fill-mode |
指定 CSS 动画在执行前后应如何将样式应用于其目标。 |
animation-play-state |
指定动画是正在运行还是暂停。 |
initial |
将此属性设置为其默认值。 |
inherit |
如果指定,则关联元素采用其父元素 动画 属性的 计算值。 |
浏览器兼容性
所有主要的现代浏览器都支持 animation 属性。
基本支持—
|
进一步阅读
请参阅以下教程: CSS3 动画.
相关属性和规则: animation-name, animation-duration, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, animation-fill-mode, animation-play-state, @keyframes.
Advertisements
