Last active
August 29, 2015 14:02
-
-
Save MadeByMike/0563ca51e08a790e553b to your computer and use it in GitHub Desktop.
Custom event 'transition-end', forget browser prefixes
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
//Custom transition end event, | |
(function(window){ | |
// Detect which transition event | |
var whichTransitionEvent = function(){ | |
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(); | |
// Create a custom 'transition-end' that wraps browser versions them | |
if (window.CustomEvent) { | |
var transitionEndEvent = new CustomEvent('transition-end',{'bubbles': true, 'cancelable': true}); | |
} else { | |
var transitionEndEvent = document.createEvent('CustomEvent'); | |
transitionEndEvent.initCustomEvent('transition-end', true, true); | |
} | |
if(transitionEvent){ | |
document.body.addEventListener(transitionEvent, function(evnt) { | |
evnt.srcElement.dispatchEvent(transitionEndEvent); | |
}); | |
} | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment