Created
March 17, 2019 00:21
-
-
Save carlohcs/7bdfc457848c758b101dad83c9984976 to your computer and use it in GitHub Desktop.
Check when the transition is finished
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
/* From Modernizr */ | |
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]; | |
} | |
} | |
} | |
/* Listen for a transition! */ | |
var transitionEvent = whichTransitionEvent(); | |
const | |
onTransitionEnd = function (el, fn) { | |
// console.log('entering here...', fn); | |
transitionEvent && el.addEventListener(transitionEvent, function() { | |
// console.log('done!'); | |
fn(); | |
}); | |
}; | |
export default onTransitionEnd; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment