Skip to content

Instantly share code, notes, and snippets.

@pgarciacamou
Created February 18, 2015 19:26
Show Gist options
  • Save pgarciacamou/29a1b0959c94356f0a17 to your computer and use it in GitHub Desktop.
Save pgarciacamou/29a1b0959c94356f0a17 to your computer and use it in GitHub Desktop.
Animation Detector. Watches for the end of and animation to execute a callback and on start you can add the proper classes to start the animation.
var Animation = (function (){
var animationEvent = (function whichAnimationEvent(){
var t, el = document.createElement("fakeelement")
,animation = null
,animations = {
"WebkitAnimation": "webkitAnimationEnd",
"MozAnimation": "animationend",
"OAnimation": "oAnimationEnd",
"animation": "animationend"
};
for(t in animations) if(!animation && el.style[t] !== undefined) {
animation = animations[t];
}
return animation;
})();
function Animation(elem){
this.elem = elem;
var self = this;
this.elem.on(animationEvent, function (){
self.isExecuting = false;
return self.onAnimationEnd && self.onAnimationEnd();
});
}
Object.defineProperties(Animation.prototype, {
'start': {
value: function (){
if(this.onAnimationStart) this.onAnimationStart();
this.isExecuting = true;
return this;
}
}
,'before': {
value: function (callback){
this.onAnimationStart = callback;
return this;
}
}
,'after': {
value: function (callback){
this.onAnimationEnd = callback;
return this;
}
}
});
return Animation;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment