When CSS3 's animation finishes an animation, we want to keep the animation in the terminating state or some other event, what do we do?
We can listen to the Webkitanimationend event,
// event at end of animation function () { console.log ("End of Animation");})
-webkit-animation animations have three events:
Start Event: Webkitanimationstart
End Event: Webkitanimationend
Repeat motion event: webkitanimationiteration
// event at start of animation function () { console.log ("animation start");}) // animations Repeat motion when events function () { console.log ("animation repeats Motion");}) // event at end of animation function () { console.log ("End of Animation");})
Example:
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metahttp-equiv= "X-ua-compatible"content= "Ie=edge,chrome=1"><title>Webkitanimationend</title><styletype= "Text/css">#div1{margin:200px Auto 0;width:200px;Height:200px;Color:#fff;Background-color:#000;-webkit-animation:Transform 3s 2 ease;}@-webkit-keyframes Transform{0%{-webkit-transform:Scale (1) rotate (50deg); }30%{-webkit-transform:Scale (2) rotate (100deg); }6%{-webkit-transform:Scale (0.5) rotate ( -100deg); }100%{-webkit-transform:Scale (1) rotate (0); }}</style></Head><Body><DivID= "Div1"></Div><Scripttype= "Text/javascript">varo=document.getElementById ("Div1");//event at start of animationO.addeventlistener ("Webkitanimationstart", function() {alert ("Animation Start");})//animations Repeat motion when eventsO.addeventlistener ("webkitanimationiteration", function() {alert ("Animation Repeat Motion");})//event at end of animationO.addeventlistener ("Webkitanimationend", function() { This. ClassName= ""; Alert ("End of animation");})</Script></Body></HTML>
CSS3 the Transition property transition, at the end of the animation, there is also an end event: webkittransitionend
Note: Transition only has this one event
Monitoring CSS3 Animation End Event-webkitanimationend