Last active
August 29, 2015 14:14
-
-
Save bugsyAlexander/bd8059f72cfc7f01dac9 to your computer and use it in GitHub Desktop.
Cross-browser "AnimationEnd" event handler with animate.css
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
| (function () { | |
| var doc = document, | |
| btnBtn = doc.getElementById("btnWrapper"); | |
| btnBtn.addEventListener("click", clickHandler, false); | |
| function clickHandler(e) { | |
| var target = e.target; | |
| if (target.nodeName === "BUTTON") { | |
| target.setAttribute("class", "animated " + target.innerHTML); | |
| } | |
| // call once animation stops | |
| prefixedEvent(target, "AnimationEnd", function () { | |
| target.removeAttribute("class"); | |
| }); | |
| } | |
| // cross-browser animationEnd_eventListener | |
| function prefixedEvent(element, type, callback) { | |
| var pfx = ["webkit", "moz", "MS", "o", ""]; | |
| for (var ii = 0; ii < pfx.length; ii++) { | |
| if (!pfx[ii]) type = type.toLowerCase(); | |
| element.addEventListener(pfx[ii] + type, callback, false); | |
| } | |
| } | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment