Skip to content

Instantly share code, notes, and snippets.

@lukewhitehouse
Created September 24, 2015 11:41
Show Gist options
  • Save lukewhitehouse/d2e4792b226505d93895 to your computer and use it in GitHub Desktop.
Save lukewhitehouse/d2e4792b226505d93895 to your computer and use it in GitHub Desktop.
On Animation or Transition end
function whichAnimationEvent(){
var t,
el = document.createElement("fakeelement");
var animations = {
"animation" : "animationend",
"OAnimation" : "oAnimationEnd",
"MozAnimation" : "animationend",
"WebkitAnimation": "webkitAnimationEnd"
}
for (t in animations){
if (el.style[t] !== undefined){
return animations[t];
}
}
}
var animationEvent = whichAnimationEvent();
// Test for animation end
$('.element').one(animationEvent, function(event) {
console.log('animation has ended');
});
function whichTransitionEvent(){
var t,
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();
// Test for transition end
$('.element').one(transitionEvent, function(event) {
console.log('transition has ended');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment