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
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:
(function() {
var i,
el = document.createElement('div'),
transitions = {
'transition':'transitionend',
'OTransition':'otransitionend', // oTransitionEnd in very old Opera
'MozTransition':'transitionend',
'WebkitTransition':'webkitTransitionEnd'
};
var transitionEnd = '';
for (i in transitions) {
if (transitions.hasOwnProperty(i) && el.style[i] !== undefined) {
transitionEnd = transitions[i];
break;
}
}
Object.prototype.onTransitionEndOnce = function(callback) {
if (transitionEnd === '') {
callback();
return this;
}
var transitionEndWrap = function(e) {
callback();
e.target.removeEventListener(e.type, transitionEndWrap);
};
this.addEventListener(transitionEnd, transitionEndWrap);
return this;
};
}());