Skip to content

Instantly share code, notes, and snippets.

@sato-shi
Forked from pgarciacamou/animation.js
Created November 27, 2015 09:55
Show Gist options
  • Save sato-shi/3b2cb774d1c59425ea26 to your computer and use it in GitHub Desktop.
Save sato-shi/3b2cb774d1c59425ea26 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