Merge pull request #30 from mStirner/animation-stop

added stop method to animation
This commit is contained in:
Frédéric Bolvin 2018-01-11 19:26:15 +01:00 committed by GitHub
commit 01f4eb2ff1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

10
anim.js
View file

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