resize animation duration on the fly
This commit is contained in:
parent
483923c79a
commit
fe4c589dc9
@ -27,10 +27,8 @@
|
||||
loop: true
|
||||
});
|
||||
|
||||
this.domainInv = torque.math.linear(this.options.animationDelay, this.options.animationDelay + this.options.animationDuration);
|
||||
this.domain = this.domainInv.invert();
|
||||
this.range = torque.math.linear(0, this.options.steps);
|
||||
this.rangeInv = this.range.invert();
|
||||
this.rescale();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -43,7 +41,13 @@
|
||||
|
||||
stop: function() {
|
||||
this.pause();
|
||||
this._time = 0;
|
||||
this.time(0);
|
||||
},
|
||||
|
||||
// real animation time
|
||||
time: function(_) {
|
||||
if (!arguments.length) return this._time;
|
||||
this._time = _;
|
||||
var t = this.range(this.domain(this._time));
|
||||
this.callback(t);
|
||||
},
|
||||
@ -56,6 +60,24 @@
|
||||
}
|
||||
},
|
||||
|
||||
rescale: function() {
|
||||
this.domainInv = torque.math.linear(this.options.animationDelay, this.options.animationDelay + this.options.animationDuration);
|
||||
this.domain = this.domainInv.invert();
|
||||
this.range = torque.math.linear(0, this.options.steps);
|
||||
this.rangeInv = this.range.invert();
|
||||
return this;
|
||||
},
|
||||
|
||||
duration: function(_) {
|
||||
if (!arguments.length) return this.options.animationDuration;
|
||||
this.options.animationDuration = _;
|
||||
this.rescale();
|
||||
if (this.time() > _) {
|
||||
this.time(0);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
step: function(s) {
|
||||
if(arguments.length === 0) return this.range(this.domain(this._time));
|
||||
this._time = this.domainInv(this.rangeInv(s));
|
||||
@ -74,9 +96,8 @@
|
||||
delta = Math.min(this.options.maxDelta, delta);
|
||||
this._t0 = t1;
|
||||
this._time += delta;
|
||||
var t = this.range(this.domain(this._time));
|
||||
this.callback(t);
|
||||
if(t >= this.options.steps) {
|
||||
this.time(this._time);
|
||||
if(this.step() >= this.options.steps) {
|
||||
this._time = 0;
|
||||
}
|
||||
if(this.running) {
|
||||
|
Loading…
Reference in New Issue
Block a user