Created
June 20, 2016 17:25
-
-
Save fatso83/2463e6f18cdc47033bb116d5fb4c4d0e to your computer and use it in GitHub Desktop.
Feature detect the actual transition end event used in the current browser. Needed for some buggy Samsung devices
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