AnimationEvent animationName Property - Javascript DOM

Javascript examples for DOM:Animation Event

Description

The animationName property returns the name of the animation, which is the value of the animation-name CSS property.

This property is read-only.

Return Value

A String, representing the name of the animation

The following code shows how to get the animation name associated with an animation:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {/*from   w ww.j ava2 s  .  c  om*/
    margin: 25px;
    width: 550px;
    height: 100px;
    background: orange;
    position: relative;
    font-size: 25px;
    -webkit-animation-name: mymove;  /* Chrome, Safari, Opera */
    -webkit-animation-duration: 5s;  /* Chrome, Safari, Opera */
    animation-name: mymove;
    animation-duration: 5s;
}

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

@keyframes mymove {
    from {top: 0px;}
    to {top: 200px;}
}
</style>
</head>
<body>

<div id="myDIV"></div>

<script>
var x = document.getElementById("myDIV");

// Code for Chrome, Safari and Opera
x.addEventListener("webkitAnimationStart", myStartFunction);

// Standard syntax
x.addEventListener("animationstart", myStartFunction);

function myStartFunction(event) {
    this.innerHTML = "The animation-name is: " + event.animationName;
}
</script>

</body>
</html>

Related Tutorials