Last active
December 23, 2015 12:19
-
-
Save neovov/6634959 to your computer and use it in GitHub Desktop.
Test if the browser support the transitionend event
This file contains hidden or 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 transitionend; | |
// Test for transitionend event | |
(function() { | |
if (!window.addEventListener) { | |
return; | |
} | |
var div = document.createElement("div"); | |
function handler(e) { | |
transitionend = e.type; | |
abort(); | |
} | |
function abort() { | |
if (div) { | |
div.parentNode.removeChild(div); | |
div = null; | |
} | |
} | |
div.setAttribute("style", "-webkit-transition: opacity 1ms; -moz-transition: opacity 1ms; -o-transition: opacity 1ms; transition: opacity 1ms"); | |
div.addEventListener("WebkitTransitionEnd", handler, false); | |
div.addEventListener("MozTransitionEnd", handler, false); | |
div.addEventListener("oTransitionEnd", handler, false); | |
div.addEventListener("transitionend", handler, false); | |
document.body.appendChild(div); | |
window.setTimeout(function() { | |
div.style.opacity = 0; | |
window.setTimeout(abort, 100); | |
}, 0); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment