Skip to content

Instantly share code, notes, and snippets.

@jmahc
Last active August 27, 2016 23:31
Show Gist options
  • Save jmahc/97f06b1d531cfce1b1d6632d6494d79a to your computer and use it in GitHub Desktop.
Save jmahc/97f06b1d531cfce1b1d6632d6494d79a to your computer and use it in GitHub Desktop.
This listens for the end of an element's CSS transition event.
(function() {
var e = document.getElementsByClassName('sample')[0];
function whichTransitionEvent(){
var t;
var 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();
transitionEvent && e.addEventListener(transitionEvent, function() {
console.log('Transition complete! This is the callback, no library needed!');
});
startFade = function() {
e.className+= ' hide';
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment