modifying public property names in spring.js, currentValue and currentTime are now current.point and current.time

This commit is contained in:
thatcher 2012-01-03 17:54:20 -05:00
parent 55f1e47156
commit 878269e0e9
2 changed files with 36 additions and 26 deletions

View File

@ -3060,18 +3060,23 @@ $.Spring = function( options ) {
$.extend( true, this, options); $.extend( true, this, options);
this.currentValue = typeof ( this.initial ) == "number" ? this.initial : 0; this.current = {
this.startValue = this.currentValue; point: typeof ( this.initial ) == "number" ?
this.targetValue = this.currentValue; this.initial :
0,
time: new Date().getTime() // always work in milliseconds
}
this.currentTime = new Date().getTime(); // always work in milliseconds this.startValue = this.current.point;
this.startTime = this.currentTime; this.startTime = this.current.time;
this.targetTime = this.currentTime;
this.targetValue = this.current.point;
this.targetTime = this.current.time;
}; };
$.Spring.prototype = { $.Spring.prototype = {
getCurrent: function() { getCurrent: function() {
return this.currentValue; return this.current.point;
}, },
getTarget: function() { getTarget: function() {
@ -3080,14 +3085,14 @@ $.Spring.prototype = {
resetTo: function(target) { resetTo: function(target) {
this.targetValue = target; this.targetValue = target;
this.targetTime = this.currentTime; this.targetTime = this.current.time;
this.startValue = this.targetValue; this.startValue = this.targetValue;
this.startTime = this.targetTime; this.startTime = this.targetTime;
}, },
springTo: function(target) { springTo: function(target) {
this.startValue = this.currentValue; this.startValue = this.current.point;
this.startTime = this.currentTime; this.startTime = this.current.time;
this.targetValue = target; this.targetValue = target;
this.targetTime = this.startTime + 1000 * this.animationTime; this.targetTime = this.startTime + 1000 * this.animationTime;
}, },
@ -3098,14 +3103,14 @@ $.Spring.prototype = {
}, },
update: function() { update: function() {
this.currentTime = new Date().getTime(); this.current.time = new Date().getTime();
this.currentValue = (this.currentTime >= this.targetTime) ? this.current.point = (this.current.time >= this.targetTime) ?
this.targetValue : this.targetValue :
this.startValue + this.startValue +
(this.targetValue - this.startValue) * (this.targetValue - this.startValue) *
transform( transform(
this.springStiffness, this.springStiffness,
(this.currentTime - this.startTime) / (this.current.time - this.startTime) /
(this.targetTime - this.startTime) (this.targetTime - this.startTime)
); );
} }

View File

@ -23,18 +23,23 @@ $.Spring = function( options ) {
$.extend( true, this, options); $.extend( true, this, options);
this.currentValue = typeof ( this.initial ) == "number" ? this.initial : 0; this.current = {
this.startValue = this.currentValue; point: typeof ( this.initial ) == "number" ?
this.targetValue = this.currentValue; this.initial :
0,
time: new Date().getTime() // always work in milliseconds
}
this.currentTime = new Date().getTime(); // always work in milliseconds this.startValue = this.current.point;
this.startTime = this.currentTime; this.startTime = this.current.time;
this.targetTime = this.currentTime;
this.targetValue = this.current.point;
this.targetTime = this.current.time;
}; };
$.Spring.prototype = { $.Spring.prototype = {
getCurrent: function() { getCurrent: function() {
return this.currentValue; return this.current.point;
}, },
getTarget: function() { getTarget: function() {
@ -43,14 +48,14 @@ $.Spring.prototype = {
resetTo: function(target) { resetTo: function(target) {
this.targetValue = target; this.targetValue = target;
this.targetTime = this.currentTime; this.targetTime = this.current.time;
this.startValue = this.targetValue; this.startValue = this.targetValue;
this.startTime = this.targetTime; this.startTime = this.targetTime;
}, },
springTo: function(target) { springTo: function(target) {
this.startValue = this.currentValue; this.startValue = this.current.point;
this.startTime = this.currentTime; this.startTime = this.current.time;
this.targetValue = target; this.targetValue = target;
this.targetTime = this.startTime + 1000 * this.animationTime; this.targetTime = this.startTime + 1000 * this.animationTime;
}, },
@ -61,14 +66,14 @@ $.Spring.prototype = {
}, },
update: function() { update: function() {
this.currentTime = new Date().getTime(); this.current.time = new Date().getTime();
this.currentValue = (this.currentTime >= this.targetTime) ? this.current.point = (this.current.time >= this.targetTime) ?
this.targetValue : this.targetValue :
this.startValue + this.startValue +
(this.targetValue - this.startValue) * (this.targetValue - this.startValue) *
transform( transform(
this.springStiffness, this.springStiffness,
(this.currentTime - this.startTime) / (this.current.time - this.startTime) /
(this.targetTime - this.startTime) (this.targetTime - this.startTime)
); );
} }