Style animationDirection 属性
改变 <div> 元素的 animationDirection 属性:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>蜜蜂教程(mifengjc.com)</title>
<style>
div {
width: 100px;
height: 100px;
background: red;
position: relative;
animation: mymove 5s infinite;
/*Safari、Chrome 和 Opera*/
-webkit-animation: mymove 5s infinite;
}
@keyframes mymove {
from {
left: 0px;
}
to {
left: 200px;
}
}
/*Safari、Chrome 和 Opera*/
@-webkit-keyframes mymove {
from {
left: 0px;
}
to {
left: 200px;
}
}
</style>
</head>
<body>
<p>点击“尝试一下”按钮方向播放动画。</p>
<button onclick="myFunction()">尝试一下</button>
<script>
function myFunction() {
document.getElementById("myDIV").style.animationDirection = "reverse";
// 针对 Chrome、Safari 和 Opera 的代码
document.getElementById("myDIV").style.WebkitAnimationDirection = "reverse";
}
</script>
<p><strong>注意:</strong>只有 Firefox 支持 animationDirection 属性。</p>
<div id="myDIV"></div>
</body>
</html>
定义和用法
animationDirection 属性设置或返回是否循环交替反向播放动画。
注意:如果动画被设置为只播放一次,该属性将不起作用。
浏览器支持
只有 Firefox 支持 animationDirection 属性。
语法
返回 animationDirection 属性:
object.style.animationDirection
设置 animationDirection 属性:
object.style.animationDirection = "normal|reverse|alternate|alternate-reverse|initial|inherit"
属性值
值 | 描述 |
---|---|
normal | 默认值。动画按正常播放。 |
reverse | 动画反向播放。 |
alternate | 动画在奇数次(1、3、5...)正向播放,在偶数次(2、4、6...)反向播放。 |
alternate-reverse | 动画在奇数次(1、3、5...)反向播放,在偶数次(2、4、6...)正向播放。 |
initial | 设置该属性为它的默认值。请参阅 initial。 |
inherit | 从父元素继承该属性。请参阅 inherit。 |
技术细节
默认值: | normal |
---|---|
返回值: | 字符串,表示元素的 animation-direction 属性。 |
CSS 版本 | CSS3 |
相关文章
CSS 参考手册:animation-direction 属性