transitionend Event - Javascript DOM

Javascript examples for DOM:TransitionEvent

Description

The transitionend event occurs when a CSS transition has completed.

Summary

Bubbles Yes
Cancelable Yes
Event type: TransitionEvent
DOM Version: Level 3 Events

The following code shows how to handle transition event.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {/*from   w w  w.j  a  va 2s .  c o m*/
    width: 100px;
    height: 100px;
    background: red;
    -webkit-transition: width 2s; /* For Safari 3.1 to 6.0 */
    transition: width 2s;
}

#myDIV:hover {
    width: 400px;
}
</style>
</head>
<body>

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

<script>
// Code for Safari 3.1 to 6.0
document.getElementById("myDIV").addEventListener("webkitTransitionEnd", myFunction);

// Standard syntax
document.getElementById("myDIV").addEventListener("transitionend", myFunction);

function myFunction() {
    this.innerHTML = "transitionend event occured - The transition has completed";
    this.style.backgroundColor = "pink";
}
</script>

</body>
</html>

Related Tutorials