Created
January 29, 2013 05:59
-
-
Save blissdev/4662153 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
var animationHelpers = { | |
determineTransition: function() { | |
// technique from: | |
// https://github.com/dmotz/oriDomi/blob/master/oridomi.js#L80 | |
// @TODO cache value so it doesn't keep getting looked up | |
var prefixList, testEl, supportedProp; | |
prefixList = ['webkit', 'Moz', 'O', 'ms', 'Khtml']; | |
testEl = document.createElement('div'); | |
supportedProp = testEl.style['transitionProperty'] != null ? | |
'transitionProperty' : | |
_.find(prefixList, function(prefix) { | |
return testEl.style[prefix + 'TransitionProperty'] != null; | |
}) + 'TransitionProperty'; | |
// deal with crossover issues between webkit & moz | |
if(supportedProp == 'transitionProperty' | |
&& testEl.style['webkitTransitionProperty'] != null) { | |
supportedProp = 'webkitNew'; | |
} | |
switch (supportedProp) { | |
case 'webkitNew': | |
return 'webkitTransitionEnd'; | |
case 'transitionProperty': | |
return 'transitionend'; | |
case 'webkitTransitionProperty': | |
return 'webkitTransitionEnd'; | |
case 'MozTransitionProperty': | |
return 'transitionend'; | |
case 'OTransitionProperty': | |
return 'oTransitionEnd'; | |
case 'MSTransitionProperty': | |
return 'msTransitionEnd'; | |
} | |
}, | |
onTransitionEnd: function(el, fn) { | |
var transition = this.determineTransition(); | |
el.addEventListener(transition, fn, false); | |
}, | |
offTransitionEnd: function(el, fn) { | |
var transition = this.determineTransition(); | |
el.removeEventListener(transition, fn, false); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment