added stop method to animation

This commit is contained in:
marc 2017-11-22 19:05:22 +01:00 committed by Frédéric Bolvin
parent a8ad19cb67
commit f558e0465a

10
anim.js
View file

@ -5,6 +5,7 @@ var resolution = 25
function Anim() {
this.fx_stack = []
this.interval = null
}
Anim.prototype.add = function(to, duration, options) {
@ -19,6 +20,13 @@ Anim.prototype.delay = function(duration) {
return this.add({}, duration)
}
Anim.prototype.stop = function () {
if(this.interval) {
clearInterval(this.interval)
}
this.fx_stack = []
}
Anim.prototype.run = function(universe, onFinish) {
var config = {}
var t = 0
@ -56,7 +64,7 @@ Anim.prototype.run = function(universe, onFinish) {
}
ani_setup()
var iid = setInterval(ani_step, resolution)
var iid = this.interval = setInterval(ani_step, resolution)
}
module.exports = Anim