Javascript DOM AnimationEvent animationName Property

Introduction

Get the animation name associated with an animation:

This example uses the addEventListener() method to attach an "animationstart" event to a DIV element.

The animationName property returns the animation name used in this animation:

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {//  ww  w . ja  v a2 s .  c o m
  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>

The animationName property returns the name of the animation, when an animation event occurs.

The name of the animation is the value of the animation-name CSS property.

This property is read-only.




PreviousNext

Related