CSS3 of the Times, css3--animation is all possible;
The traditional JS can judge whether the animation is finished by the callback function, even if the animation effect is generated by CSS technology, JavaScript can still capture the animated or transformed end event.
Transitionend Event and Animationend event standard browser events, but in WebKit browsers you still need to use the WebKit prefix, so we have to detect events based on various browsers
Copy Code code as follows:
var transitions = {
' Transition ': ' Transitionend ',
' Otransition ': ' Otransitionend ',
' Moztransition ': ' Transitionend ',
' Webkittransition ': ' Webkittransitionend '
}
The source code is attached below:
Copy Code code as follows:
<!doctype html>
<meta charset= "Utf-8" >
<title>suface JS to determine whether the CSS animation is over </title>
<body>
<p> once the animation or transformation is finished, the callback function is triggered. Large class library support is no longer required. <br> </p>
<style type= "Text/css" >
. Sample {
width:200px;
height:200px;
border:1px solid Green;
Background:lightgreen;
Opacity:1;
margin-bottom:20px;
transition-property:opacity;
/*transition-duration:. 5s;*/
transition-duration:3s;
}
. sample.hide {
opacity:0;
}
</style>
<div class= "Sample" >css3 animation too slowly hide (transition-duration:3s;) </div>
<p><button onclick= "this.style.display= ' None"; Startfade (); " > Slowly fade, Detect end Event </button></p>
<script>
(function () {
var e = document.getelementsbyclassname (' sample ') [0];
function Whichtransitionevent () {
var T;
var el = document.createelement (' fakeelement ');
var transitions = {
' Transition ': ' Transitionend ',
' Otransition ': ' Otransitionend ',
' Moztransition ': ' Transitionend ',
' Webkittransition ': ' Webkittransitionend '
}
for (t in transitions) {
if (El.style[t]!== undefined) {
return transitions[t];
}
}
}
var transitionevent = whichtransitionevent ();
Transitionevent && E.addeventlistener (transitionevent, function () {
Alert (' CSS3 campaign is over! I am the callback function, not using the third party class library! ');
});
Startfade = function () {
e.classname+= ' hide ';
}
}) ();<br></script>
</body>
This is the method described in this article about JavaScript judgment CSS3 animation end, I hope you can enjoy