Skip to content

Instantly share code, notes, and snippets.

@bugsyAlexander
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save bugsyAlexander/bd8059f72cfc7f01dac9 to your computer and use it in GitHub Desktop.

Select an option

Save bugsyAlexander/bd8059f72cfc7f01dac9 to your computer and use it in GitHub Desktop.
Cross-browser "AnimationEnd" event handler with animate.css
(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