From f558e0465af9e8009373979774b11d40b721770a Mon Sep 17 00:00:00 2001 From: marc Date: Wed, 22 Nov 2017 19:05:22 +0100 Subject: [PATCH] added stop method to animation --- anim.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/anim.js b/anim.js index 614fff3..e4ebff3 100644 --- a/anim.js +++ b/anim.js @@ -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 \ No newline at end of file +module.exports = Anim