I'd like to delete an object after it's done animating with a CSS transition, but I'm not able to use a JavaScript library.
How do I detect when the animation is done? Do I use a callback or custom event somehow?
I'd like to delete an object after it's done animating with a CSS transition, but I'm not able to use a JavaScript library.
How do I detect when the animation is done? Do I use a callback or custom event somehow?
I was unable to find a suitable 'transitionend' polyfill that met my requirements. So if you want something for hooking the transition end once, use this:
As I'm currently doing the exact same thing I'll share a useful, cross-browser implementation from a Marakana tutorial.
It's to be noted that IE10 supports transitions with
transitionend
(see MSDN).IE9 and below do not support transitions (see caniuse.com ) so you won't be able to attach any eventListener to a transition end ( so don't try
msTransitionend
or whatever for those browsers).EDIT: While reading Modernizr documentation on Github I stumbled on their cross-browser polyfills page. Among many other useful links I found this small but extremely good transitionend script.
Mind that the examples in the Github README.md use jQuery but the library indeed requires no libraries and no dependencies as it's written in vanilla javascript.
For now, the exact event name has not been standardized. Here's a quote from MDN:
Here's the fiddle for Webkit: http://jsfiddle.net/bNgWY/