CSS animation-direction 属性
CSS animation-direction 属性指示动画是否反向播放,它通常在简写属性 animation 中设定。
实例
暂停动画:
<!DOCTYPE html><html><head><style>div{width:100px;height:100px;background:red;position:relative;animation:myfirst 5s infinite;animation-direction:alternate;/* Safari and Chrome */-webkit-animation:myfirst 5s infinite;-webkit-animation-direction:alternate;}@keyframes myfirst{0% {background:red; left:0px; top:0px;}25% {background:yellow; left:200px; top:0px;}50% {background:blue; left:200px; top:200px;}75% {background:green; left:0px; top:200px;}100% {background:red; left:0px; top:0px;}}@-webkit-keyframes myfirst /* Safari and Chrome */{0% {background:red; left:0px; top:0px;}25% {background:yellow; left:200px; top:0px;}50% {background:blue; left:200px; top:200px;}75% {background:green; left:0px; top:200px;}100% {background:red; left:0px; top:0px;}}</style></head><body><p><strong>注释:</strong>Internet Explorer 9 以及更早的版本不支持 animation-direction 属性。</p><div></div></body></html>
浏览器支持
表格中的数字注明了完全支持该属性的首个浏览器版本。
带 -webkit-、-moz- 或 -o- 的数字表示使用前缀的首个版本。
| 属性 | |||||
|---|---|---|---|---|---|
| animation-direction | 43.04.0 -webkit- | 10.0 | 16.05.0 -moz- | 9.04.0 -webkit- | 30.015.0 -webkit-12.0 -o- |
定义和用法
animation-direction 属性定义是否应该轮流反向播放动画。
如果 animation-direction 值是 "alternate",则动画会在奇数次数(1、3、5 等等)正常播放,而在偶数次数(2、4、6 等等)向后播放。
注释:如果把动画设置为只播放一次,则该属性没有效果。
| 默认值: | normal |
|---|---|
| 继承性: | no |
| 版本: | CSS3 |
| JavaScript 语法: | object.style.animationDirection="alternate" |
语法
animation-direction: normal|alternate;
| 值 | 描述 |
|---|---|
| normal | 默认值。动画应该正常播放。 |
| alternate | 动画应该交替反向播放。 |
| reverse | 反向运行动画,每周期结束动画由尾到头运行。 |
| alternate-reverse | 反向交替, 反向开始交替。 |
相关页面
CSS3 教程:CSS3 动画