The animationDuration
property gets and sets
how many seconds or milliseconds an animation takes to complete one cycle.
animationDuration |
4.0 -webkit- | 10.0 | 16.0 (5.0 -moz-) | 4.0 -webkit- | 15.0 -webkit- (12.0 -o-) |
Return the animationDuration property:
var v = object.style.animationDuration;
Set the animationDuration property:
object.style.animationDuration='time|initial|inherit'
Default Value: | 0 |
---|---|
Return Value: | A string representing the animation-duration property |
CSS Version | CSS3 |
The following code shows how to change the animationDuration property of a <div> element.
<!DOCTYPE html>
<html>
<head>
<style>
div {<!--from w w w .ja v a2 s . com-->
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.WebkitAnimationDuration = "1s"; // Code for Chrome, Safari, and Opera
document.getElementById("myDIV").style.animationDuration = "1s";
}
</script>
<div id="myDIV"></div>
</body>
</html>
The code above is rendered as follows: