How can you detect which CSS animation just finished in JavaScript?
The ultimate need is to re-trigger a CSS animation. Due to our HTML hierarchy, we prefer not checking the element’s class but instead taking action only when a particular animation ends. If you have a method that allows re-triggering an animation without removing/adding a class, please let us know.
Otherwise… our code:
page.find( '.button.letter' ).on( 'webkitAnimationEnd', function() {
$( this ).removeClass( 'tap_animation' );
console.log( 'Hi: ' + this.style.webkitAnimationName );
if ( !write_mode() ) {
do_write( this );
}
});
this.style.webkitAnimationName always returns the empty string.
Are we doing something wrong?
We need the code for WebKit browsers, specifically Mobile Safari.
Thanks!
From jQuery you can access the
originalEventobject, and, from there, theanimationNameproperty:(Webkit-only) JS Fiddle demo.
From there, simply use an
ifto check what the animation name is/was (past-tense, I suppose, given that it ended).The above updated, to give possibly a better illustration:
(Webkit-only) JS Fiddle demo.
This demo uses the following HTML:
And CSS: