Created
April 11, 2017 08:31
-
-
Save fatso83/39fd2cea69892de0fa503752a8b6b715 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
// globals: window, document, $ | |
// | |
// Feature detect the actual transitionFinished event | |
// used by the current browser | |
// | |
// Used like this: | |
// var features = {}; | |
// transitionEndFeatureDetection((eventName) => { | |
// features.transitionFinishedEvent = eventName; | |
// }); | |
function transitionEndFeatureDetection (callback) { | |
// Defines prefixed versions of the | |
// transitionEnd event handler | |
var transitionFinishedEvents = { | |
'WebkitTransition' : 'webkitTransitionEnd', | |
'MozTransition' : 'transitionend', | |
'OTransition' : 'oTransitionEnd', | |
'msTransition' : 'msTransitionEnd', | |
'transition' : 'transitionEnd' | |
}; | |
var div = document.createElement('div'); | |
div.id = "my-transition-test"; | |
div.style.position = 'absolute'; | |
div.style.zIndex = -10; | |
div.style.bottom = '-1000px'; | |
div.style.height = '100px'; | |
div.style.width = '100px'; | |
div.style.background = 'yellow'; | |
div.style.display = 'hidden'; | |
document.body.appendChild(div); | |
$('#my-transition-test').one(_.values(transitionFinishedEvents).join(" "), function (e) { | |
callback(e.type); | |
document.body.removeChild(div); | |
// alternative: div.parentNode.removeChild(div); | |
}); | |
// schedule a transition to happen on next tick | |
setTimeout(function () { | |
div.style[$M.prefixed('transition')] = '10ms'; | |
div.style[$M.prefixed('transform')] = 'translate3d( 100px,0,0)'; | |
}, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment