Skip to content

Instantly share code, notes, and snippets.

@fatso83
Created June 20, 2016 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fatso83/2463e6f18cdc47033bb116d5fb4c4d0e to your computer and use it in GitHub Desktop.
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
// 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