public
Created

  • Download Gist
transition_sniffing.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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];
}
}
}

Two questions, please.

1 -
Is it really needed to do fake element?
document.body has some bugs or wrong behavior?

2 - WebkitTransition. it is strange that in console present only lower case webkitTransition.
And from IE9 this works el.style.setProperty("-webkit-transition", "left 2s linear");
http://jsfiddle.net/7b4VZ/3/

I would suggest to simply register all transitionend events for all vendors. do we really need to spoof them?

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) { ...

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.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.