Javascript DOM CSS Style animationDuration Property

Introduction

Changing the animationDuration property of a <div> element:

document.getElementById("myDIV").style.animationDuration = "3s";

Click the button to speed up the duration of the animation.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
div {/*from   w  w w. j a v  a  2  s  .c o  m*/
  width: 100px;
  height: 100px;
  background: red;
  position: relative;
  animation: mymove 5s infinite;
}

@keyframes mymove {
  from {left: 0px;}
  to {left: 200px;}
}
</style>
</head>
<body>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {
  document.getElementById("myDIV").style.animationDuration = "1s";
}
</script>
<div id="myDIV"></div>

</body>
</html>

The animationDuration property defines how many seconds or milliseconds an animation takes to complete one cycle.

Property Values

Value Description
timeSets the length an animation takes to finish. Default value is 0, meaning there will be no animation
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

The animationDuration property returns a String representing the animation-duration property of an element.




PreviousNext

Related