Skip to content

Instantly share code, notes, and snippets.

@fatso83
Last active December 31, 2015 07:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fatso83/5714040 to your computer and use it in GitHub Desktop.
Save fatso83/5714040 to your computer and use it in GitHub Desktop.
This feature detects the actual event name used by the browser for transitionEnd . This might differ from Modernizr.prefixed('transition'). Known browsers+device affected by this: Chrome 27.0.1453.93 on Desktop/OS X, Android 4.1.2 browser running on Samsung Note II
// Defines prefixed versions of the
// transitionEnd event handler
transitionFinishedEvents = {
'WebkitTransition' : 'webkitTransitionEnd',
'MozTransition' : 'transitionend',
'OTransition' : 'oTransitionEnd',
'msTransition' : 'msTransitionEnd',
'transition' : 'transitionEnd'
};
// Define the correct transition event for this UA
$M.transitionFinishedEvent = transitionFinishedEvents[ $M.prefixed('transition') ];
// Feature detect actual transitionEnd keyword by triggering an event
window.setTimeout(function () {
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';
window.document.body.appendChild(div);
$('#my-transition-test').one(_.values(transitionFinishedEvents).join(" "), function (e) {
if ($M.transitionFinishedEvent !== e.type) {
window.console.warn("Changing misconfigured Modernizr.transitionFinishedEvent to " + e.type + ". (Was " + $M.transitionFinishedEvent + ")");
$M.transitionFinishedEvent = e.type;
}
window.document.body.removeChild(div);
});
window.setTimeout(function () {
div.style[$M.prefixed('transition')] = '0.1s';
div.style[$M.prefixed('transform')] = 'translate3d( 100px,0,0)';
}, 25);
}, 25);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment