-
-
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.
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
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