Created
December 30, 2012 20:04
-
-
Save maccman/4414792 to your computer and use it in GitHub Desktop.
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
function whichTransitionEvent(){ | |
var t; | |
var el = document.createElement('fakeelement'); | |
var transitions = { | |
'transition':'transitionend', | |
'MSTransition':'msTransitionEnd', | |
'MozTransition':'transitionend', | |
'WebkitTransition':'webkitTransitionEnd' | |
} | |
for(t in transitions){ | |
if( el.style[t] !== undefined ){ | |
return transitions[t]; | |
} | |
} | |
} |
You shouldn't register all events. The reason for this is that at least Chrome as of version 29 will fire off both webkitTransitionEnd and transitionend. So your function will fire twice.
The way you get around firing function twice is to add a namespace to the event name and turning them all off once one of them have been executed.
this.$el.on('webkitTransitionEnd.blah transitionend.blah msTransitionEnd.blah oTransitionEnd.blah', function(event) {
this.$el.off(".blah");
}
Obviously, replace blah
with your own namespace.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have successfully used callbacks by registering the events for all browsers so i would recommend that.
eg:
this.$el.on('webkitTransitionEnd transitionend msTransitionEnd oTransitionEnd', function(event) { ...