Last active
August 27, 2016 23:31
-
-
Save jmahc/97f06b1d531cfce1b1d6632d6494d79a to your computer and use it in GitHub Desktop.
This listens for the end of an element's CSS transition event.
This file contains hidden or 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
(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