2
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.net/yui/license.txt
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.
36
* @param {Number} t Time value used to compute current value
37
* @param {Number} b Starting value
38
* @param {Number} c Delta between start and end values
39
* @param {Number} d Total length of animation
40
* @return {Number} The computed value for the current animation frame
42
easeNone: function (t, b, c, d) {
47
* Begins slowly and accelerates towards end. (quadratic)
49
* @param {Number} t Time value used to compute current value
50
* @param {Number} b Starting value
51
* @param {Number} c Delta between start and end values
52
* @param {Number} d Total length of animation
53
* @return {Number} The computed value for the current animation frame
55
easeIn: function (t, b, c, d) {
56
return c*(t/=d)*t + b;
60
* Begins quickly and decelerates towards end. (quadratic)
62
* @param {Number} t Time value used to compute current value
63
* @param {Number} b Starting value
64
* @param {Number} c Delta between start and end values
65
* @param {Number} d Total length of animation
66
* @return {Number} The computed value for the current animation frame
68
easeOut: function (t, b, c, d) {
69
return -c *(t/=d)*(t-2) + b;
73
* Begins slowly and decelerates towards end. (quadratic)
75
* @param {Number} t Time value used to compute current value
76
* @param {Number} b Starting value
77
* @param {Number} c Delta between start and end values
78
* @param {Number} d Total length of animation
79
* @return {Number} The computed value for the current animation frame
81
easeBoth: function (t, b, c, d) {
86
return -c/2 * ((--t)*(t-2) - 1) + b;
90
* Begins slowly and accelerates towards end. (quartic)
91
* @method easeInStrong
92
* @param {Number} t Time value used to compute current value
93
* @param {Number} b Starting value
94
* @param {Number} c Delta between start and end values
95
* @param {Number} d Total length of animation
96
* @return {Number} The computed value for the current animation frame
98
easeInStrong: function (t, b, c, d) {
99
return c*(t/=d)*t*t*t + b;
103
* Begins quickly and decelerates towards end. (quartic)
104
* @method easeOutStrong
105
* @param {Number} t Time value used to compute current value
106
* @param {Number} b Starting value
107
* @param {Number} c Delta between start and end values
108
* @param {Number} d Total length of animation
109
* @return {Number} The computed value for the current animation frame
111
easeOutStrong: function (t, b, c, d) {
112
return -c * ((t=t/d-1)*t*t*t - 1) + b;
116
* Begins slowly and decelerates towards end. (quartic)
117
* @method easeBothStrong
118
* @param {Number} t Time value used to compute current value
119
* @param {Number} b Starting value
120
* @param {Number} c Delta between start and end values
121
* @param {Number} d Total length of animation
122
* @return {Number} The computed value for the current animation frame
124
easeBothStrong: function (t, b, c, d) {
126
return c/2*t*t*t*t + b;
129
return -c/2 * ((t-=2)*t*t*t - 2) + b;
133
* Snap in elastic effect.
135
* @param {Number} t Time value used to compute current value
136
* @param {Number} b Starting value
137
* @param {Number} c Delta between start and end values
138
* @param {Number} d Total length of animation
139
* @param {Number} a Amplitude (optional)
140
* @param {Number} p Period (optional)
141
* @return {Number} The computed value for the current animation frame
144
elasticIn: function (t, b, c, d, a, p) {
149
if ( (t /= d) === 1 ) {
156
if (!a || a < Math.abs(c)) {
161
s = p/(2*Math.PI) * Math.asin (c/a);
164
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
168
* Snap out elastic effect.
170
* @param {Number} t Time value used to compute current value
171
* @param {Number} b Starting value
172
* @param {Number} c Delta between start and end values
173
* @param {Number} d Total length of animation
174
* @param {Number} a Amplitude (optional)
175
* @param {Number} p Period (optional)
176
* @return {Number} The computed value for the current animation frame
178
elasticOut: function (t, b, c, d, a, p) {
183
if ( (t /= d) === 1 ) {
190
if (!a || a < Math.abs(c)) {
195
s = p/(2*Math.PI) * Math.asin (c/a);
198
return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
202
* Snap both elastic effect.
203
* @method elasticBoth
204
* @param {Number} t Time value used to compute current value
205
* @param {Number} b Starting value
206
* @param {Number} c Delta between start and end values
207
* @param {Number} d Total length of animation
208
* @param {Number} a Amplitude (optional)
209
* @param {Number} p Period (optional)
210
* @return {Number} The computed value for the current animation frame
212
elasticBoth: function (t, b, c, d, a, p) {
218
if ( (t /= d/2) === 2 ) {
226
if ( !a || a < Math.abs(c) ) {
231
s = p/(2*Math.PI) * Math.asin (c/a);
235
return -0.5*(a*Math.pow(2,10*(t-=1)) *
236
Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
238
return a*Math.pow(2,-10*(t-=1)) *
239
Math.sin( (t*d-s)*(2*Math.PI)/p )*0.5 + c + b;
244
* Backtracks slightly, then reverses direction and moves to end.
246
* @param {Number} t Time value used to compute current value
247
* @param {Number} b Starting value
248
* @param {Number} c Delta between start and end values
249
* @param {Number} d Total length of animation
250
* @param {Number} s Overshoot (optional)
251
* @return {Number} The computed value for the current animation frame
253
backIn: function (t, b, c, d, s) {
254
if (s == undefined) {
260
return c*(t/=d)*t*((s+1)*t - s) + b;
264
* Overshoots end, then reverses and comes back to end.
266
* @param {Number} t Time value used to compute current value
267
* @param {Number} b Starting value
268
* @param {Number} c Delta between start and end values
269
* @param {Number} d Total length of animation
270
* @param {Number} s Overshoot (optional)
271
* @return {Number} The computed value for the current animation frame
273
backOut: function (t, b, c, d, s) {
274
if (typeof s === 'undefined') {
277
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
281
* Backtracks slightly, then reverses direction, overshoots end,
282
* then reverses and comes back to end.
284
* @param {Number} t Time value used to compute current value
285
* @param {Number} b Starting value
286
* @param {Number} c Delta between start and end values
287
* @param {Number} d Total length of animation
288
* @param {Number} s Overshoot (optional)
289
* @return {Number} The computed value for the current animation frame
291
backBoth: function (t, b, c, d, s) {
292
if (typeof s === 'undefined') {
296
if ((t /= d/2 ) < 1) {
297
return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
299
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
303
* Bounce off of start.
305
* @param {Number} t Time value used to compute current value
306
* @param {Number} b Starting value
307
* @param {Number} c Delta between start and end values
308
* @param {Number} d Total length of animation
309
* @return {Number} The computed value for the current animation frame
311
bounceIn: function (t, b, c, d) {
312
return c - Y.Easing.bounceOut(d-t, 0, c, d) + b;
318
* @param {Number} t Time value used to compute current value
319
* @param {Number} b Starting value
320
* @param {Number} c Delta between start and end values
321
* @param {Number} d Total length of animation
322
* @return {Number} The computed value for the current animation frame
324
bounceOut: function (t, b, c, d) {
325
if ((t/=d) < (1/2.75)) {
326
return c*(7.5625*t*t) + b;
327
} else if (t < (2/2.75)) {
328
return c*(7.5625*(t-=(1.5/2.75))*t + 0.75) + b;
329
} else if (t < (2.5/2.75)) {
330
return c*(7.5625*(t-=(2.25/2.75))*t + 0.9375) + b;
332
return c*(7.5625*(t-=(2.625/2.75))*t + 0.984375) + b;
336
* Bounces off start and end.
338
* @param {Number} t Time value used to compute current value
339
* @param {Number} b Starting value
340
* @param {Number} c Delta between start and end values
341
* @param {Number} d Total length of animation
342
* @return {Number} The computed value for the current animation frame
344
bounceBoth: function (t, b, c, d) {
346
return Y.Easing.bounceIn(t * 2, 0, c, d) * 0.5 + b;
348
return Y.Easing.bounceOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
353
}, '3.0.0pr1' ,{requires:['anim-base']});