JavaScript onanimationend Event
You are Here:
JavaScript onanimationend Event
The onanimationend
event occurs when a CSS Animation has completed.
Note: The onanimationend
event will not fire if the CSS animation is aborted before completion.
onanimationend Event as Attribute
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<head>
<style>
h2 {
color: blue;
-webkit-animation: myMultiColor 2s;
animation: myMultiColor 2s;
}
/* Safari 4.0 - 8.0 */
@-webkit-keyframes myMultiColor {
from {color: blue;}
to {color: green;}
}
/* Standard syntax */
@keyframes myMultiColor {
from {color: blue;}
to {color: green;}
}
</style>
</head>
<body>
<h2 onanimationend="myFunction()">Animation is Awesome</h2>
<p id="point"></p>
<script>
function myFunction() {
document.getElementById("point").innerHTML = "Animation ended";
}
</script>
</body>
</html>
Syntax
As Attribute
<element onanimationend = "JavaScript">
As Property
window.onanimationend = function(){
// code
};
Using Event Listener
object.addEventListener("animationend" , myScript);
onanimationend Event as Property
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<head>
<style>
h2 {
color: blue;
-webkit-animation: myMultiColor 2s;
animation: myMultiColor 2s;
}
/* Safari 4.0 - 8.0 */
@-webkit-keyframes myMultiColor {
from {color: blue;}
to {color: green;}
}
/* Standard syntax */
@keyframes myMultiColor {
from {color: blue;}
to {color: green;}
}
</style>
</head>
<body>
<h2>Animation is Awesome</h2>
<p id="point"></p>
<script>
function myFunction() {
document.getElementById("point").innerHTML = "Animation ended";
}
window.onanimationend = myFunction;
</script>
</body>
</html>
Using addEventListener() Method
Note: The addEventListener() method is not supported in Internet Explorer 8 and below.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<head>
<style>
h2 {
color: blue;
-webkit-animation: myMultiColor 2s;
animation: myMultiColor 2s;
}
/* Safari 4.0 - 8.0 */
@-webkit-keyframes myMultiColor {
from {color: blue;}
to {color: green;}
}
/* Standard syntax */
@keyframes myMultiColor {
from {color: blue;}
to {color: green;}
}
</style>
</head>
<body>
<h2>Animation is Awesome</h2>
<p id="point"></p>
<script>
var x = document.getElementsByTagName("h2")[0];
function myFunction() {
document.getElementById("point").innerHTML = "Animation ended";
}
x.addEventListener("animationend", myFunction);
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.