Javascript Reference - HTML DOM Style animationName Property








The animationName property sets or gets a name for the @keyframes animation.

Browser Support

animationName Yes (WebkitAnimationName) 10 Yes Yes (WebkitAnimationName) Yes (WebkitAnimationName)

Syntax

Return the animationName property:

var v = object.style.animationName 

Set the animationName property:

object.style.animationName=none|keyframename|initial|inherit

Property Values

keyframename
set the name of the keyframe
none(Default value)
no animation




Technical Details

Default Value: none
Return Value: A string representing the animation-name property
CSS Version CSS3

Example

The following code shows how to change the animationName property of a <div> element.


<!DOCTYPE html>
<html>
<head>
<style> 
div {<!--from   ww  w  .  j  av  a 2 s. c o  m-->
    width: 100px;
    height: 100px;
    background: red;
    position: relative;
    -webkit-animation: mymove 2s infinite;  /* Chrome, Safari, Opera */
    animation: mymove 2s infinite;
}

/* Chrome, Safari, Opera */
@-webkit-keyframes mymove {
    from {left: 0px;}
    to {left: 250px;}
}

@keyframes mymove {
    from {left: 0px;}
    to {left: 250px;}
}

/* Chrome, Safari, Opera */
@-webkit-keyframes myNew {
    from {width: 0px;}
    to {width: 500px; background: blue;}
}

@keyframes myNew {
    from {width: 0px;}
    to {width: 500px; background: blue;}
}
</style>
</head>
<body>
<button onclick="myFunction()">test</button>

<script>
function myFunction() {
    document.getElementById("myDIV").style.WebkitAnimationName = "myNew"; // Code for Chrome, Safari, and Opera
    document.getElementById("myDIV").style.animationName = "myNew";
}
</script>
<div id="myDIV"></div>
</body>
</html>

The code above is rendered as follows: