JavaScript onanimationstart Event

You are Here:

JavaScript onanimationstart Event

The onanimationstart event occurs when a CSS Animation has started.

Note: If there is an animation-delay, this event will fire once the delay period has expired.

onanimationstart Event as Attribute

Example

HTML Online Editor
<!DOCTYPE html> <html> <head> <style> h2 { color: blue; -webkit-animation: myMultiColor 1s infinite; animation: myMultiColor 1s infinite; } /* 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 onanimationstart="myFunction()">Animation is Awesome</h2> <p id="point"></p> <script> function myFunction() { document.getElementById("point").innerHTML = "Animation started!"; } </script> </body> </html>

Syntax

As Attribute

<element onanimationstart = "JavaScript">

As Property

window.onanimationstart = function(){ // code };

Using Event Listener

object.addEventListener("animationstart" , myScript);

onanimationstart Event as Property

Example

HTML Online Editor
<!DOCTYPE html> <html> <head> <style> h2 { color: blue; -webkit-animation: myMultiColor 1s infinite; animation: myMultiColor 1s infinite; } /* 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 started!"; } window.onanimationstart = 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 1s infinite; animation: myMultiColor 1s infinite; } /* 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 started!"; } x.addEventListener("animationstart", 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.

Share this Page

Meet the Author