2013-05-11 13:10:05 +08:00
|
|
|
(function() {
|
|
|
|
var blacklist = {
|
|
|
|
node: 1,
|
|
|
|
duration: 1,
|
2013-05-12 14:57:14 +08:00
|
|
|
easing: 1,
|
2013-05-12 07:43:09 +08:00
|
|
|
onFinish: 1,
|
2013-05-11 13:10:05 +08:00
|
|
|
yoyo: 1
|
|
|
|
},
|
|
|
|
|
|
|
|
PAUSED = 1,
|
|
|
|
PLAYING = 2,
|
2013-06-04 12:50:14 +08:00
|
|
|
REVERSING = 3,
|
2013-05-11 13:10:05 +08:00
|
|
|
|
2013-06-04 12:50:14 +08:00
|
|
|
idCounter = 0;
|
2013-05-11 13:10:05 +08:00
|
|
|
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
2013-05-19 01:40:05 +08:00
|
|
|
* Tween constructor. Tweens enable you to animate a node between the current state and a new state.
|
|
|
|
* You can play, pause, reverse, seek, reset, and finish tweens. By default, tweens are animated using
|
|
|
|
* a linear easing. For more tweening options, check out {@link Kinetic.Easings}
|
2013-05-16 13:03:52 +08:00
|
|
|
* @constructor
|
|
|
|
* @memberof Kinetic
|
2013-05-19 01:40:05 +08:00
|
|
|
* @example
|
|
|
|
* // instantiate new tween which fully rotates a node in 1 second
|
|
|
|
* var tween = new Kinetic.Tween({<br>
|
|
|
|
* node: node,<br>
|
|
|
|
* rotationDeg: 360,<br>
|
|
|
|
* duration: 1,<br>
|
2013-05-19 13:30:57 +08:00
|
|
|
* easing: Kinetic.Easings.EaseInOut<br>
|
2013-05-19 01:40:05 +08:00
|
|
|
* });<br><br>
|
|
|
|
*
|
|
|
|
* // play tween<br>
|
|
|
|
* tween.play();<br><br>
|
|
|
|
*
|
|
|
|
* // pause tween<br>
|
|
|
|
* tween.pause();
|
2013-05-16 13:03:52 +08:00
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
Kinetic.Tween = function(config) {
|
|
|
|
var that = this,
|
|
|
|
node = config.node,
|
2013-05-12 07:43:09 +08:00
|
|
|
nodeId = node._id,
|
2013-05-11 13:10:05 +08:00
|
|
|
duration = config.duration || 1,
|
2013-05-12 14:57:14 +08:00
|
|
|
easing = config.easing || Kinetic.Easings.Linear,
|
2013-05-11 13:10:05 +08:00
|
|
|
yoyo = !!config.yoyo,
|
2013-06-04 12:50:14 +08:00
|
|
|
key, tween, start, tweenId;
|
2013-05-11 13:10:05 +08:00
|
|
|
|
2013-05-12 07:43:09 +08:00
|
|
|
this.node = node;
|
2013-06-04 12:50:14 +08:00
|
|
|
this._id = idCounter++;
|
2013-05-12 07:43:09 +08:00
|
|
|
this.onFinish = config.onFinish;
|
|
|
|
|
|
|
|
this.anim = new Kinetic.Animation(function() {
|
2013-06-04 12:50:14 +08:00
|
|
|
that.tween.onEnterFrame();
|
2013-05-20 12:07:43 +08:00
|
|
|
}, node.getLayer() || node.getLayers());
|
2013-05-11 13:10:05 +08:00
|
|
|
|
2013-06-04 12:50:14 +08:00
|
|
|
this.tween = new Tween(key, function(i) {
|
|
|
|
that._tweenFunc(i);
|
|
|
|
}, easing, 0, 1, duration * 1000, yoyo);
|
|
|
|
|
|
|
|
this._addListeners();
|
|
|
|
|
|
|
|
// init attrs map
|
|
|
|
if (!Kinetic.Tween.attrs[nodeId]) {
|
|
|
|
Kinetic.Tween.attrs[nodeId] = {};
|
|
|
|
}
|
|
|
|
if (!Kinetic.Tween.attrs[nodeId][this._id]) {
|
|
|
|
Kinetic.Tween.attrs[nodeId][this._id] = {};
|
|
|
|
}
|
|
|
|
// init tweens map
|
|
|
|
if (!Kinetic.Tween.tweens[nodeId]) {
|
|
|
|
Kinetic.Tween.tweens[nodeId] = {};
|
|
|
|
}
|
|
|
|
|
2013-05-11 13:10:05 +08:00
|
|
|
for (key in config) {
|
|
|
|
if (blacklist[key] === undefined) {
|
2013-06-05 13:39:11 +08:00
|
|
|
this._addAttr(key, config[key]);
|
2013-05-11 13:10:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.reset();
|
|
|
|
};
|
|
|
|
|
2013-06-04 12:50:14 +08:00
|
|
|
Kinetic.Tween.attrs = {};
|
2013-05-12 07:43:09 +08:00
|
|
|
Kinetic.Tween.tweens = {};
|
|
|
|
|
2013-06-04 12:50:14 +08:00
|
|
|
Kinetic.Tween.prototype = {
|
2013-06-05 13:39:11 +08:00
|
|
|
_addAttr: function(key, end) {
|
2013-06-04 12:50:14 +08:00
|
|
|
var node = this.node,
|
|
|
|
nodeId = node._id,
|
2013-06-04 13:09:47 +08:00
|
|
|
start, diff, tweenId, n, len, startVal, endVal;
|
2013-05-12 07:43:09 +08:00
|
|
|
|
2013-06-04 12:50:14 +08:00
|
|
|
// remove conflict from tween map if it exists
|
|
|
|
tweenId = Kinetic.Tween.tweens[nodeId][key];
|
2013-05-12 07:43:09 +08:00
|
|
|
|
2013-06-04 12:50:14 +08:00
|
|
|
if (tweenId) {
|
|
|
|
delete Kinetic.Tween.attrs[nodeId][tweenId][key];
|
|
|
|
}
|
2013-05-12 07:43:09 +08:00
|
|
|
|
2013-06-04 12:50:14 +08:00
|
|
|
// add to tween map
|
2013-06-05 13:39:11 +08:00
|
|
|
start = node.getAttr(key);
|
2013-06-04 13:09:47 +08:00
|
|
|
|
|
|
|
if (Kinetic.Util._isArray(end)) {
|
|
|
|
end = Kinetic.Util._getPoints(end);
|
|
|
|
diff = [];
|
|
|
|
len = end.length;
|
|
|
|
for (n=0; n<len; n++) {
|
|
|
|
startVal = start[n];
|
|
|
|
endVal = end[n];
|
|
|
|
diff.push({
|
|
|
|
x: endVal.x - startVal.x,
|
|
|
|
y: endVal.y - startVal.y
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
diff = end - start;
|
|
|
|
}
|
|
|
|
|
2013-06-04 12:50:14 +08:00
|
|
|
Kinetic.Tween.attrs[nodeId][this._id][key] = {
|
|
|
|
start: start,
|
2013-06-04 13:09:47 +08:00
|
|
|
diff: diff
|
2013-06-04 12:50:14 +08:00
|
|
|
};
|
|
|
|
Kinetic.Tween.tweens[nodeId][key] = this._id;
|
2013-05-11 13:10:05 +08:00
|
|
|
},
|
2013-06-04 12:50:14 +08:00
|
|
|
_tweenFunc: function(i) {
|
|
|
|
var node = this.node,
|
|
|
|
attrs = Kinetic.Tween.attrs[node._id][this._id],
|
2013-06-04 13:09:47 +08:00
|
|
|
key, attr, start, diff, newVal, n, len, startVal, diffVal;
|
2013-06-04 12:50:14 +08:00
|
|
|
|
|
|
|
for (key in attrs) {
|
|
|
|
attr = attrs[key];
|
|
|
|
start = attr.start;
|
|
|
|
diff = attr.diff;
|
2013-06-04 13:09:47 +08:00
|
|
|
|
|
|
|
if (Kinetic.Util._isArray(start)) {
|
|
|
|
newVal = [];
|
|
|
|
len = start.length;
|
|
|
|
for (n=0; n<len; n++) {
|
|
|
|
startVal = start[n];
|
|
|
|
diffVal = diff[n];
|
|
|
|
newVal.push({
|
|
|
|
x: startVal.x + (diffVal.x * i),
|
|
|
|
y: startVal.y + (diffVal.y * i)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newVal = start + (diff * i);
|
|
|
|
}
|
|
|
|
|
2013-06-05 13:39:11 +08:00
|
|
|
node.setAttr(key, newVal);
|
2013-06-04 12:50:14 +08:00
|
|
|
}
|
2013-05-21 13:41:13 +08:00
|
|
|
},
|
2013-06-04 12:50:14 +08:00
|
|
|
_addListeners: function() {
|
2013-05-12 07:43:09 +08:00
|
|
|
var that = this;
|
2013-05-11 13:10:05 +08:00
|
|
|
|
2013-05-12 07:43:09 +08:00
|
|
|
// start listeners
|
2013-06-04 12:50:14 +08:00
|
|
|
this.tween.onPlay = function() {
|
|
|
|
that.anim.start();
|
2013-05-12 07:43:09 +08:00
|
|
|
};
|
2013-06-04 12:50:14 +08:00
|
|
|
this.tween.onReverse = function() {
|
|
|
|
that.anim.start();
|
2013-05-12 07:43:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// stop listeners
|
2013-06-04 12:50:14 +08:00
|
|
|
this.tween.onPause = function() {
|
|
|
|
that.anim.stop();
|
2013-05-12 07:43:09 +08:00
|
|
|
};
|
2013-06-04 12:50:14 +08:00
|
|
|
this.tween.onFinish = function() {
|
|
|
|
if (that.onFinish) {
|
2013-05-12 07:43:09 +08:00
|
|
|
that.onFinish();
|
|
|
|
}
|
|
|
|
};
|
2013-05-11 13:10:05 +08:00
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* play
|
|
|
|
* @method
|
|
|
|
* @memberof Kinetic.Tween.prototype
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
play: function() {
|
2013-06-04 12:50:14 +08:00
|
|
|
this.tween.play();
|
2013-06-05 13:39:11 +08:00
|
|
|
return this;
|
2013-05-11 13:10:05 +08:00
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* reverse
|
|
|
|
* @method
|
|
|
|
* @memberof Kinetic.Tween.prototype
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
reverse: function() {
|
2013-06-04 12:50:14 +08:00
|
|
|
this.tween.reverse();
|
2013-06-05 13:39:11 +08:00
|
|
|
return this;
|
2013-05-11 13:10:05 +08:00
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* reset
|
|
|
|
* @method
|
|
|
|
* @memberof Kinetic.Tween.prototype
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
reset: function() {
|
2013-05-20 12:07:43 +08:00
|
|
|
var node = this.node;
|
2013-06-04 12:50:14 +08:00
|
|
|
this.tween.reset();
|
2013-05-20 12:07:43 +08:00
|
|
|
(node.getLayer() || node.getLayers()).draw();
|
2013-06-05 13:39:11 +08:00
|
|
|
return this;
|
2013-05-11 13:10:05 +08:00
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* seek
|
|
|
|
* @method
|
|
|
|
* @memberof Kinetic.Tween.prototype
|
|
|
|
* @param {Integer} t time in seconds between 0 and the duration
|
|
|
|
*/
|
2013-05-12 07:43:09 +08:00
|
|
|
seek: function(t) {
|
2013-05-21 14:35:05 +08:00
|
|
|
var node = this.node;
|
2013-06-04 12:50:14 +08:00
|
|
|
this.tween.seek(t * 1000);
|
2013-05-20 12:07:43 +08:00
|
|
|
(node.getLayer() || node.getLayers()).draw();
|
2013-06-05 13:39:11 +08:00
|
|
|
return this;
|
2013-05-11 13:10:05 +08:00
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* pause
|
|
|
|
* @method
|
|
|
|
* @memberof Kinetic.Tween.prototype
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
pause: function() {
|
2013-06-09 11:22:34 +08:00
|
|
|
this.tween.pause();
|
2013-06-05 13:39:11 +08:00
|
|
|
return this;
|
2013-05-12 07:43:09 +08:00
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* finish
|
|
|
|
* @method
|
|
|
|
* @memberof Kinetic.Tween.prototype
|
|
|
|
*/
|
2013-05-12 07:43:09 +08:00
|
|
|
finish: function() {
|
2013-05-21 14:35:05 +08:00
|
|
|
var node = this.node;
|
2013-06-04 12:50:14 +08:00
|
|
|
this.tween.finish();
|
2013-05-20 12:07:43 +08:00
|
|
|
(node.getLayer() || node.getLayers()).draw();
|
2013-06-05 13:39:11 +08:00
|
|
|
return this;
|
2013-05-11 13:10:05 +08:00
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* destroy
|
|
|
|
* @method
|
|
|
|
* @memberof Kinetic.Tween.prototype
|
|
|
|
*/
|
2013-05-12 07:43:09 +08:00
|
|
|
destroy: function() {
|
|
|
|
|
2013-05-11 13:10:05 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-12 07:43:09 +08:00
|
|
|
var Tween = function(prop, propFunc, func, begin, finish, duration, yoyo) {
|
|
|
|
this.prop = prop;
|
2013-05-11 13:10:05 +08:00
|
|
|
this.propFunc = propFunc;
|
|
|
|
this.begin = begin;
|
|
|
|
this._pos = begin;
|
|
|
|
this.duration = duration;
|
|
|
|
this._change = 0;
|
|
|
|
this.prevPos = 0;
|
|
|
|
this.yoyo = yoyo;
|
|
|
|
this._time = 0;
|
|
|
|
this._position = 0;
|
|
|
|
this._startTime = 0;
|
|
|
|
this._finish = 0;
|
|
|
|
this.func = func;
|
|
|
|
this._change = finish - this.begin;
|
2013-05-12 07:43:09 +08:00
|
|
|
this.pause();
|
2013-05-11 13:10:05 +08:00
|
|
|
};
|
|
|
|
/*
|
|
|
|
* Tween methods
|
|
|
|
*/
|
|
|
|
Tween.prototype = {
|
2013-05-12 07:43:09 +08:00
|
|
|
fire: function(str) {
|
|
|
|
var handler = this[str];
|
|
|
|
if (handler) {
|
|
|
|
handler();
|
|
|
|
}
|
|
|
|
},
|
2013-05-11 13:10:05 +08:00
|
|
|
setTime: function(t) {
|
|
|
|
if(t > this.duration) {
|
|
|
|
if(this.yoyo) {
|
|
|
|
this._time = this.duration;
|
|
|
|
this.reverse();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(t < 0) {
|
|
|
|
if(this.yoyo) {
|
|
|
|
this._time = 0;
|
|
|
|
this.play();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._time = t;
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getTime: function() {
|
|
|
|
return this._time;
|
|
|
|
},
|
|
|
|
setPosition: function(p) {
|
|
|
|
this.prevPos = this._pos;
|
|
|
|
this.propFunc(p);
|
|
|
|
this._pos = p;
|
|
|
|
},
|
|
|
|
getPosition: function(t) {
|
|
|
|
if(t === undefined) {
|
|
|
|
t = this._time;
|
|
|
|
}
|
|
|
|
return this.func(t, this.begin, this._change, this.duration);
|
|
|
|
},
|
|
|
|
play: function() {
|
|
|
|
this.state = PLAYING;
|
|
|
|
this._startTime = this.getTimer() - this._time;
|
|
|
|
this.onEnterFrame();
|
2013-05-12 07:43:09 +08:00
|
|
|
this.fire('onPlay');
|
2013-05-11 13:10:05 +08:00
|
|
|
},
|
|
|
|
reverse: function() {
|
|
|
|
this.state = REVERSING;
|
|
|
|
this._time = this.duration - this._time;
|
|
|
|
this._startTime = this.getTimer() - this._time;
|
|
|
|
this.onEnterFrame();
|
2013-05-12 07:43:09 +08:00
|
|
|
this.fire('onReverse');
|
2013-05-11 13:10:05 +08:00
|
|
|
},
|
2013-05-12 07:43:09 +08:00
|
|
|
seek: function(t) {
|
2013-05-12 07:48:24 +08:00
|
|
|
this.pause();
|
2013-05-11 13:10:05 +08:00
|
|
|
this._time = t;
|
|
|
|
this.update();
|
2013-05-12 07:43:09 +08:00
|
|
|
this.fire('onSeek');
|
2013-05-11 13:10:05 +08:00
|
|
|
},
|
|
|
|
reset: function() {
|
|
|
|
this.pause();
|
|
|
|
this._time = 0;
|
|
|
|
this.update();
|
2013-05-12 07:43:09 +08:00
|
|
|
this.fire('onReset');
|
2013-05-11 13:10:05 +08:00
|
|
|
},
|
|
|
|
finish: function() {
|
|
|
|
this.pause();
|
|
|
|
this._time = this.duration;
|
|
|
|
this.update();
|
2013-05-12 07:43:09 +08:00
|
|
|
this.fire('onFinish');
|
2013-05-11 13:10:05 +08:00
|
|
|
},
|
|
|
|
update: function() {
|
|
|
|
this.setPosition(this.getPosition(this._time));
|
|
|
|
},
|
|
|
|
onEnterFrame: function() {
|
|
|
|
var t = this.getTimer() - this._startTime;
|
|
|
|
if(this.state === PLAYING) {
|
|
|
|
this.setTime(t);
|
|
|
|
}
|
|
|
|
else if (this.state === REVERSING) {
|
|
|
|
this.setTime(this.duration - t);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
pause: function() {
|
|
|
|
this.state = PAUSED;
|
2013-05-12 07:43:09 +08:00
|
|
|
this.fire('onPause');
|
2013-05-11 13:10:05 +08:00
|
|
|
},
|
|
|
|
getTimer: function() {
|
|
|
|
return new Date().getTime();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2013-05-12 07:43:09 +08:00
|
|
|
* These eases were ported from an Adobe Flash tweening library to JavaScript
|
2013-05-11 13:10:05 +08:00
|
|
|
* by Xaric
|
|
|
|
*/
|
2013-05-16 13:03:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @namespace Easings
|
|
|
|
* @memberof Kinetic
|
|
|
|
*/
|
2013-05-12 14:57:14 +08:00
|
|
|
Kinetic.Easings = {
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* back ease in
|
|
|
|
* @function
|
|
|
|
* @memberof Kinetic.Easings
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
'BackEaseIn': function(t, b, c, d, a, p) {
|
|
|
|
var s = 1.70158;
|
|
|
|
return c * (t /= d) * t * ((s + 1) * t - s) + b;
|
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* back ease out
|
|
|
|
* @function
|
|
|
|
* @memberof Kinetic.Easings
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
'BackEaseOut': function(t, b, c, d, a, p) {
|
|
|
|
var s = 1.70158;
|
|
|
|
return c * (( t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
|
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* back ease in out
|
|
|
|
* @function
|
|
|
|
* @memberof Kinetic.Easings
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
'BackEaseInOut': function(t, b, c, d, a, p) {
|
|
|
|
var s = 1.70158;
|
|
|
|
if((t /= d / 2) < 1) {
|
|
|
|
return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
|
|
|
|
}
|
|
|
|
return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
|
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* elastic ease in
|
|
|
|
* @function
|
|
|
|
* @memberof Kinetic.Easings
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
'ElasticEaseIn': function(t, b, c, d, a, p) {
|
|
|
|
// added s = 0
|
|
|
|
var s = 0;
|
|
|
|
if(t === 0) {
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
if((t /= d) == 1) {
|
|
|
|
return b + c;
|
|
|
|
}
|
|
|
|
if(!p) {
|
|
|
|
p = d * 0.3;
|
|
|
|
}
|
|
|
|
if(!a || a < Math.abs(c)) {
|
|
|
|
a = c;
|
|
|
|
s = p / 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
s = p / (2 * Math.PI) * Math.asin(c / a);
|
|
|
|
}
|
|
|
|
return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
|
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* elastic ease out
|
|
|
|
* @function
|
|
|
|
* @memberof Kinetic.Easings
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
'ElasticEaseOut': function(t, b, c, d, a, p) {
|
|
|
|
// added s = 0
|
|
|
|
var s = 0;
|
|
|
|
if(t === 0) {
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
if((t /= d) == 1) {
|
|
|
|
return b + c;
|
|
|
|
}
|
|
|
|
if(!p) {
|
|
|
|
p = d * 0.3;
|
|
|
|
}
|
|
|
|
if(!a || a < Math.abs(c)) {
|
|
|
|
a = c;
|
|
|
|
s = p / 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
s = p / (2 * Math.PI) * Math.asin(c / a);
|
|
|
|
}
|
|
|
|
return (a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b);
|
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* elastic ease in out
|
|
|
|
* @function
|
|
|
|
* @memberof Kinetic.Easings
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
'ElasticEaseInOut': function(t, b, c, d, a, p) {
|
|
|
|
// added s = 0
|
|
|
|
var s = 0;
|
|
|
|
if(t === 0) {
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
if((t /= d / 2) == 2) {
|
|
|
|
return b + c;
|
|
|
|
}
|
|
|
|
if(!p) {
|
|
|
|
p = d * (0.3 * 1.5);
|
|
|
|
}
|
|
|
|
if(!a || a < Math.abs(c)) {
|
|
|
|
a = c;
|
|
|
|
s = p / 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
s = p / (2 * Math.PI) * Math.asin(c / a);
|
|
|
|
}
|
|
|
|
if(t < 1) {
|
|
|
|
return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
|
|
|
|
}
|
|
|
|
return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * 0.5 + c + b;
|
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* bounce ease out
|
|
|
|
* @function
|
|
|
|
* @memberof Kinetic.Easings
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
'BounceEaseOut': function(t, b, c, d) {
|
|
|
|
if((t /= d) < (1 / 2.75)) {
|
|
|
|
return c * (7.5625 * t * t) + b;
|
|
|
|
}
|
|
|
|
else if(t < (2 / 2.75)) {
|
|
|
|
return c * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75) + b;
|
|
|
|
}
|
|
|
|
else if(t < (2.5 / 2.75)) {
|
|
|
|
return c * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375) + b;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return c * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375) + b;
|
|
|
|
}
|
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* bounce ease in
|
|
|
|
* @function
|
|
|
|
* @memberof Kinetic.Easings
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
'BounceEaseIn': function(t, b, c, d) {
|
2013-05-12 14:57:14 +08:00
|
|
|
return c - Kinetic.Easings.BounceEaseOut(d - t, 0, c, d) + b;
|
2013-05-11 13:10:05 +08:00
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* bounce ease in out
|
|
|
|
* @function
|
|
|
|
* @memberof Kinetic.Easings
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
'BounceEaseInOut': function(t, b, c, d) {
|
|
|
|
if(t < d / 2) {
|
2013-05-12 14:57:14 +08:00
|
|
|
return Kinetic.Easings.BounceEaseIn(t * 2, 0, c, d) * 0.5 + b;
|
2013-05-11 13:10:05 +08:00
|
|
|
}
|
|
|
|
else {
|
2013-05-12 14:57:14 +08:00
|
|
|
return Kinetic.Easings.BounceEaseOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
|
2013-05-11 13:10:05 +08:00
|
|
|
}
|
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* ease in
|
|
|
|
* @function
|
|
|
|
* @memberof Kinetic.Easings
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
'EaseIn': function(t, b, c, d) {
|
|
|
|
return c * (t /= d) * t + b;
|
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* ease out
|
|
|
|
* @function
|
|
|
|
* @memberof Kinetic.Easings
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
'EaseOut': function(t, b, c, d) {
|
|
|
|
return -c * (t /= d) * (t - 2) + b;
|
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* ease in out
|
|
|
|
* @function
|
|
|
|
* @memberof Kinetic.Easings
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
'EaseInOut': function(t, b, c, d) {
|
|
|
|
if((t /= d / 2) < 1) {
|
|
|
|
return c / 2 * t * t + b;
|
|
|
|
}
|
|
|
|
return -c / 2 * ((--t) * (t - 2) - 1) + b;
|
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* strong ease in
|
|
|
|
* @function
|
|
|
|
* @memberof Kinetic.Easings
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
'StrongEaseIn': function(t, b, c, d) {
|
|
|
|
return c * (t /= d) * t * t * t * t + b;
|
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* strong ease out
|
|
|
|
* @function
|
|
|
|
* @memberof Kinetic.Easings
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
'StrongEaseOut': function(t, b, c, d) {
|
|
|
|
return c * (( t = t / d - 1) * t * t * t * t + 1) + b;
|
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* strong ease in out
|
|
|
|
* @function
|
|
|
|
* @memberof Kinetic.Easings
|
|
|
|
*/
|
2013-05-12 14:57:14 +08:00
|
|
|
'StrongEaseInOut': function(t, b, c, d) {
|
2013-05-11 13:10:05 +08:00
|
|
|
if((t /= d / 2) < 1) {
|
|
|
|
return c / 2 * t * t * t * t * t + b;
|
|
|
|
}
|
|
|
|
return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
|
|
|
|
},
|
2013-05-16 13:03:52 +08:00
|
|
|
/**
|
|
|
|
* linear
|
|
|
|
* @function
|
|
|
|
* @memberof Kinetic.Easings
|
|
|
|
*/
|
2013-05-11 13:10:05 +08:00
|
|
|
'Linear': function(t, b, c, d) {
|
|
|
|
return c * t / d + b;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})();
|