3
Copyright 2012 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('anim-easing', function(Y) {
10
TERMS OF USE - EASING EQUATIONS
11
Open source under the BSD License.
12
Copyright 2001 Robert Penner All rights reserved.
14
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
16
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
17
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
18
* Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
20
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
* The easing module provides methods for customizing
25
* how an animation behaves during each run.
28
* @submodule anim-easing
34
* Uniform speed between points.
37
* @param {Number} t Time value used to compute current value
38
* @param {Number} b Starting value
39
* @param {Number} c Delta between start and end values
40
* @param {Number} d Total length of animation
41
* @return {Number} The computed value for the current animation frame
43
easeNone: function (t, b, c, d) {
48
* Begins slowly and accelerates towards end. (quadratic)
50
* @param {Number} t Time value used to compute current value
51
* @param {Number} b Starting value
52
* @param {Number} c Delta between start and end values
53
* @param {Number} d Total length of animation
54
* @return {Number} The computed value for the current animation frame
56
easeIn: function (t, b, c, d) {
57
return c*(t/=d)*t + b;
61
* Begins quickly and decelerates towards end. (quadratic)
63
* @param {Number} t Time value used to compute current value
64
* @param {Number} b Starting value
65
* @param {Number} c Delta between start and end values
66
* @param {Number} d Total length of animation
67
* @return {Number} The computed value for the current animation frame
69
easeOut: function (t, b, c, d) {
70
return -c *(t/=d)*(t-2) + b;
74
* Begins slowly and decelerates towards end. (quadratic)
76
* @param {Number} t Time value used to compute current value
77
* @param {Number} b Starting value
78
* @param {Number} c Delta between start and end values
79
* @param {Number} d Total length of animation
80
* @return {Number} The computed value for the current animation frame
82
easeBoth: function (t, b, c, d) {
87
return -c/2 * ((--t)*(t-2) - 1) + b;
91
* Begins slowly and accelerates towards end. (quartic)
92
* @method easeInStrong
93
* @param {Number} t Time value used to compute current value
94
* @param {Number} b Starting value
95
* @param {Number} c Delta between start and end values
96
* @param {Number} d Total length of animation
97
* @return {Number} The computed value for the current animation frame
99
easeInStrong: function (t, b, c, d) {
100
return c*(t/=d)*t*t*t + b;
104
* Begins quickly and decelerates towards end. (quartic)
105
* @method easeOutStrong
106
* @param {Number} t Time value used to compute current value
107
* @param {Number} b Starting value
108
* @param {Number} c Delta between start and end values
109
* @param {Number} d Total length of animation
110
* @return {Number} The computed value for the current animation frame
112
easeOutStrong: function (t, b, c, d) {
113
return -c * ((t=t/d-1)*t*t*t - 1) + b;
117
* Begins slowly and decelerates towards end. (quartic)
118
* @method easeBothStrong
119
* @param {Number} t Time value used to compute current value
120
* @param {Number} b Starting value
121
* @param {Number} c Delta between start and end values
122
* @param {Number} d Total length of animation
123
* @return {Number} The computed value for the current animation frame
125
easeBothStrong: function (t, b, c, d) {
127
return c/2*t*t*t*t + b;
130
return -c/2 * ((t-=2)*t*t*t - 2) + b;
134
* Snap in elastic effect.
136
* @param {Number} t Time value used to compute current value
137
* @param {Number} b Starting value
138
* @param {Number} c Delta between start and end values
139
* @param {Number} d Total length of animation
140
* @param {Number} a Amplitude (optional)
141
* @param {Number} p Period (optional)
142
* @return {Number} The computed value for the current animation frame
145
elasticIn: function (t, b, c, d, a, p) {
150
if ( (t /= d) === 1 ) {
157
if (!a || a < Math.abs(c)) {
162
s = p/(2*Math.PI) * Math.asin (c/a);
165
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
169
* Snap out elastic effect.
171
* @param {Number} t Time value used to compute current value
172
* @param {Number} b Starting value
173
* @param {Number} c Delta between start and end values
174
* @param {Number} d Total length of animation
175
* @param {Number} a Amplitude (optional)
176
* @param {Number} p Period (optional)
177
* @return {Number} The computed value for the current animation frame
179
elasticOut: function (t, b, c, d, a, p) {
184
if ( (t /= d) === 1 ) {
191
if (!a || a < Math.abs(c)) {
196
s = p/(2*Math.PI) * Math.asin (c/a);
199
return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
203
* Snap both elastic effect.
204
* @method elasticBoth
205
* @param {Number} t Time value used to compute current value
206
* @param {Number} b Starting value
207
* @param {Number} c Delta between start and end values
208
* @param {Number} d Total length of animation
209
* @param {Number} a Amplitude (optional)
210
* @param {Number} p Period (optional)
211
* @return {Number} The computed value for the current animation frame
213
elasticBoth: function (t, b, c, d, a, p) {
219
if ( (t /= d/2) === 2 ) {
227
if ( !a || a < Math.abs(c) ) {
232
s = p/(2*Math.PI) * Math.asin (c/a);
236
return -0.5*(a*Math.pow(2,10*(t-=1)) *
237
Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
239
return a*Math.pow(2,-10*(t-=1)) *
240
Math.sin( (t*d-s)*(2*Math.PI)/p )*0.5 + c + b;
245
* Backtracks slightly, then reverses direction and moves to end.
247
* @param {Number} t Time value used to compute current value
248
* @param {Number} b Starting value
249
* @param {Number} c Delta between start and end values
250
* @param {Number} d Total length of animation
251
* @param {Number} s Overshoot (optional)
252
* @return {Number} The computed value for the current animation frame
254
backIn: function (t, b, c, d, s) {
255
if (s === undefined) {
261
return c*(t/=d)*t*((s+1)*t - s) + b;
265
* Overshoots end, then reverses and comes back to end.
267
* @param {Number} t Time value used to compute current value
268
* @param {Number} b Starting value
269
* @param {Number} c Delta between start and end values
270
* @param {Number} d Total length of animation
271
* @param {Number} s Overshoot (optional)
272
* @return {Number} The computed value for the current animation frame
274
backOut: function (t, b, c, d, s) {
275
if (typeof s === 'undefined') {
278
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
282
* Backtracks slightly, then reverses direction, overshoots end,
283
* then reverses and comes back to end.
285
* @param {Number} t Time value used to compute current value
286
* @param {Number} b Starting value
287
* @param {Number} c Delta between start and end values
288
* @param {Number} d Total length of animation
289
* @param {Number} s Overshoot (optional)
290
* @return {Number} The computed value for the current animation frame
292
backBoth: function (t, b, c, d, s) {
293
if (typeof s === 'undefined') {
297
if ((t /= d/2 ) < 1) {
298
return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
300
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
304
* Bounce off of start.
306
* @param {Number} t Time value used to compute current value
307
* @param {Number} b Starting value
308
* @param {Number} c Delta between start and end values
309
* @param {Number} d Total length of animation
310
* @return {Number} The computed value for the current animation frame
312
bounceIn: function (t, b, c, d) {
313
return c - Y.Easing.bounceOut(d-t, 0, c, d) + b;
319
* @param {Number} t Time value used to compute current value
320
* @param {Number} b Starting value
321
* @param {Number} c Delta between start and end values
322
* @param {Number} d Total length of animation
323
* @return {Number} The computed value for the current animation frame
325
bounceOut: function (t, b, c, d) {
326
if ((t/=d) < (1/2.75)) {
327
return c*(7.5625*t*t) + b;
328
} else if (t < (2/2.75)) {
329
return c*(7.5625*(t-=(1.5/2.75))*t + 0.75) + b;
330
} else if (t < (2.5/2.75)) {
331
return c*(7.5625*(t-=(2.25/2.75))*t + 0.9375) + b;
333
return c*(7.5625*(t-=(2.625/2.75))*t + 0.984375) + b;
337
* Bounces off start and end.
339
* @param {Number} t Time value used to compute current value
340
* @param {Number} b Starting value
341
* @param {Number} c Delta between start and end values
342
* @param {Number} d Total length of animation
343
* @return {Number} The computed value for the current animation frame
345
bounceBoth: function (t, b, c, d) {
347
return Y.Easing.bounceIn(t * 2, 0, c, d) * 0.5 + b;
349
return Y.Easing.bounceOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
356
}, '3.5.1' ,{requires:['anim-base']});