Created
April 15, 2015 18:01
-
-
Save jdsharp/947e3c9750fb3e4e8f2c to your computer and use it in GitHub Desktop.
Animation and Transition Events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inspiration via: http://davidwalsh.name/css-animation-callback | |
var addAnimationEndEvent = function(el, fn) { | |
var t; | |
var animations = { | |
'animation' : 'animationend', | |
'OAnimation' : 'oAnimationEnd', | |
'MozAnimation' : 'animationend', | |
'WebkitAnimation' : 'webkitAnimationEnd' | |
}; | |
for (t in animations) { | |
if ( typeof el.style[t] !== 'undefined' ) { | |
el.addEventListener(animations[t], fn); | |
return true; | |
} | |
} | |
return false; | |
}; | |
var removeAnimationEndEvent = function(el, fn) { | |
var t; | |
var animations = { | |
'animation' : 'animationend', | |
'OAnimation' : 'oAnimationEnd', | |
'MozAnimation' : 'animationend', | |
'WebkitAnimation' : 'webkitAnimationEnd' | |
}; | |
for (t in animations) { | |
if ( typeof el.style[t] !== 'undefined' ) { | |
el.removeEventListener(animations[t], fn); | |
return true; | |
} | |
} | |
return false; | |
}; | |
var addTransitionEndEvent = function(el, fn) { | |
var t; | |
var transitions = { | |
'transition' : 'transitionend', | |
'OTransition' : 'oTransitionEnd', | |
'MozTransition' : 'transitionend', | |
'WebkitTransition' : 'webkitTransitionEnd' | |
}; | |
for (t in transitions) { | |
if ( typeof el.style[t] !== 'undefined' ) { | |
el.addEventListener(transitions[t], fn); | |
return true; | |
} | |
} | |
return false; | |
}; | |
var removeTransitionEndEvent = function(el, fn) { | |
var t; | |
var transitions = { | |
'transition' : 'transitionend', | |
'OTransition' : 'oTransitionEnd', | |
'MozTransition' : 'transitionend', | |
'WebkitTransition' : 'webkitTransitionEnd' | |
}; | |
for (t in transitions) { | |
if ( typeof el.style[t] !== 'undefined' ) { | |
el.removeEventListener(transitions[t], fn); | |
return true; | |
} | |
} | |
return false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment