Skip to content

Instantly share code, notes, and snippets.

@dmjcomdem
Created October 11, 2017 09:59
Show Gist options
  • Save dmjcomdem/9ae0aaaf4e4d24ed33f02e5bf884c0e6 to your computer and use it in GitHub Desktop.
Save dmjcomdem/9ae0aaaf4e4d24ed33f02e5bf884c0e6 to your computer and use it in GitHub Desktop.
Detect the supported event property name
function whichTransitionEvent(){
var t,
el = document.createElement("fakeelement");
var transitions = {
"transition" : "transitionend",
"OTransition" : "oTransitionEnd",
"MozTransition" : "transitionend",
"WebkitTransition": "webkitTransitionEnd"
}
for (t in transitions){
if (el.style[t] !== undefined){
return transitions[t];
}
}
}
var transitionEvent = whichTransitionEvent();
$(".button").click(function(){
$(this).addClass("animate");
$(this).one(transitionEvent,
function(event) {
// Do something when the transition ends
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment