The animationDirection
property sets or gets whether
to play the animation in reverse on alternate cycles.
Style animationDirection |
No | No | Yes | No | No |
Return the animationDirection property:
var v = object.style.animationDirection;
Set the animationDirection property:
object.style.animationDirection='normal|reverse|alternate|alternate-reverse|initial|inherit'
Default Value: | normal |
---|---|
Return Value: | A string representing the animation-direction property |
CSS Version | CSS3 |
The following code shows how to change the animationDirection property of a <div> element.
<!DOCTYPE html>
<html>
<head>
<style>
div {<!-- ww w .ja v a 2s . c o m-->
width: 100px;
height: 100px;
background: red;
position: relative;
-webkit-animation: mymove 5s infinite; /* Chrome, Safari, Opera */
animation: mymove 5s infinite;
}
/* Chrome, Safari, Opera */
@-webkit-keyframes mymove {
from {left: 0px;}
to {left: 200px;}
}
@keyframes mymove {
from {left: 0px;}
to {left: 200px;}
}
</style>
</head>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myDIV").style.WebkitAnimationDirection = "reverse"; // Code for Chrome, Safari, and Opera
document.getElementById("myDIV").style.animationDirection = "reverse";
}
</script>
<div id="myDIV"></div>
</body>
</html>
The code above is rendered as follows: