1
/* YUI 3.9.1 (build 5852) Copyright 2013 Yahoo! Inc. http://yuilibrary.com/license/ */
2
YUI.add('anim-easing', function (Y, NAME) {
5
TERMS OF USE - EASING EQUATIONS
6
Open source under the BSD License.
7
Copyright 2001 Robert Penner All rights reserved.
9
Redistribution and use in source and binary forms, with or without modification,
10
are permitted provided that the following conditions are met:
12
* Redistributions of source code must retain the above copyright notice, this
13
list of conditions and the following disclaimer.
14
* Redistributions in binary form must reproduce the above copyright notice,
15
this list of conditions and the following disclaimer in the documentation
16
and/or other materials provided with the distribution.
17
* Neither the name of the author nor the names of contributors may be used to
18
endorse or promote products derived from this software without specific prior
21
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
28
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30
OF THE POSSIBILITY OF SUCH DAMAGE.
34
* The easing module provides methods for customizing
35
* how an animation behaves during each run.
38
* @submodule anim-easing
44
* Uniform speed between points.
47
* @param {Number} t Time value used to compute current value
48
* @param {Number} b Starting value
49
* @param {Number} c Delta between start and end values
50
* @param {Number} d Total length of animation
51
* @return {Number} The computed value for the current animation frame
53
easeNone: function (t, b, c, d) {
58
* Begins slowly and accelerates towards end. (quadratic)
60
* @param {Number} t Time value used to compute current value
61
* @param {Number} b Starting value
62
* @param {Number} c Delta between start and end values
63
* @param {Number} d Total length of animation
64
* @return {Number} The computed value for the current animation frame
66
easeIn: function (t, b, c, d) {
67
return c*(t/=d)*t + b;
71
* Begins quickly and decelerates towards end. (quadratic)
73
* @param {Number} t Time value used to compute current value
74
* @param {Number} b Starting value
75
* @param {Number} c Delta between start and end values
76
* @param {Number} d Total length of animation
77
* @return {Number} The computed value for the current animation frame
79
easeOut: function (t, b, c, d) {
80
return -c *(t/=d)*(t-2) + b;
84
* Begins slowly and decelerates towards end. (quadratic)
86
* @param {Number} t Time value used to compute current value
87
* @param {Number} b Starting value
88
* @param {Number} c Delta between start and end values
89
* @param {Number} d Total length of animation
90
* @return {Number} The computed value for the current animation frame
92
easeBoth: function (t, b, c, d) {
97
return -c/2 * ((--t)*(t-2) - 1) + b;
101
* Begins slowly and accelerates towards end. (quartic)
102
* @method easeInStrong
103
* @param {Number} t Time value used to compute current value
104
* @param {Number} b Starting value
105
* @param {Number} c Delta between start and end values
106
* @param {Number} d Total length of animation
107
* @return {Number} The computed value for the current animation frame
109
easeInStrong: function (t, b, c, d) {
110
return c*(t/=d)*t*t*t + b;
114
* Begins quickly and decelerates towards end. (quartic)
115
* @method easeOutStrong
116
* @param {Number} t Time value used to compute current value
117
* @param {Number} b Starting value
118
* @param {Number} c Delta between start and end values
119
* @param {Number} d Total length of animation
120
* @return {Number} The computed value for the current animation frame
122
easeOutStrong: function (t, b, c, d) {
123
return -c * ((t=t/d-1)*t*t*t - 1) + b;
127
* Begins slowly and decelerates towards end. (quartic)
128
* @method easeBothStrong
129
* @param {Number} t Time value used to compute current value
130
* @param {Number} b Starting value
131
* @param {Number} c Delta between start and end values
132
* @param {Number} d Total length of animation
133
* @return {Number} The computed value for the current animation frame
135
easeBothStrong: function (t, b, c, d) {
136
if ((t /= d/2) < 1) {
137
return c/2*t*t*t*t + b;
140
return -c/2 * ((t-=2)*t*t*t - 2) + b;
144
* Snap in elastic effect.
146
* @param {Number} t Time value used to compute current value
147
* @param {Number} b Starting value
148
* @param {Number} c Delta between start and end values
149
* @param {Number} d Total length of animation
150
* @param {Number} a Amplitude (optional)
151
* @param {Number} p Period (optional)
152
* @return {Number} The computed value for the current animation frame
155
elasticIn: function (t, b, c, d, a, p) {
160
if ( (t /= d) === 1 ) {
167
if (!a || a < Math.abs(c)) {
172
s = p/(2*Math.PI) * Math.asin (c/a);
175
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
179
* Snap out elastic effect.
181
* @param {Number} t Time value used to compute current value
182
* @param {Number} b Starting value
183
* @param {Number} c Delta between start and end values
184
* @param {Number} d Total length of animation
185
* @param {Number} a Amplitude (optional)
186
* @param {Number} p Period (optional)
187
* @return {Number} The computed value for the current animation frame
189
elasticOut: function (t, b, c, d, a, p) {
194
if ( (t /= d) === 1 ) {
201
if (!a || a < Math.abs(c)) {
206
s = p/(2*Math.PI) * Math.asin (c/a);
209
return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
213
* Snap both elastic effect.
214
* @method elasticBoth
215
* @param {Number} t Time value used to compute current value
216
* @param {Number} b Starting value
217
* @param {Number} c Delta between start and end values
218
* @param {Number} d Total length of animation
219
* @param {Number} a Amplitude (optional)
220
* @param {Number} p Period (optional)
221
* @return {Number} The computed value for the current animation frame
223
elasticBoth: function (t, b, c, d, a, p) {
229
if ( (t /= d/2) === 2 ) {
237
if ( !a || a < Math.abs(c) ) {
242
s = p/(2*Math.PI) * Math.asin (c/a);
246
return -0.5*(a*Math.pow(2,10*(t-=1)) *
247
Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
249
return a*Math.pow(2,-10*(t-=1)) *
250
Math.sin( (t*d-s)*(2*Math.PI)/p )*0.5 + c + b;
255
* Backtracks slightly, then reverses direction and moves to end.
257
* @param {Number} t Time value used to compute current value
258
* @param {Number} b Starting value
259
* @param {Number} c Delta between start and end values
260
* @param {Number} d Total length of animation
261
* @param {Number} s Overshoot (optional)
262
* @return {Number} The computed value for the current animation frame
264
backIn: function (t, b, c, d, s) {
265
if (s === undefined) {
271
return c*(t/=d)*t*((s+1)*t - s) + b;
275
* Overshoots end, then reverses and comes back to end.
277
* @param {Number} t Time value used to compute current value
278
* @param {Number} b Starting value
279
* @param {Number} c Delta between start and end values
280
* @param {Number} d Total length of animation
281
* @param {Number} s Overshoot (optional)
282
* @return {Number} The computed value for the current animation frame
284
backOut: function (t, b, c, d, s) {
285
if (typeof s === 'undefined') {
288
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
292
* Backtracks slightly, then reverses direction, overshoots end,
293
* then reverses and comes back to end.
295
* @param {Number} t Time value used to compute current value
296
* @param {Number} b Starting value
297
* @param {Number} c Delta between start and end values
298
* @param {Number} d Total length of animation
299
* @param {Number} s Overshoot (optional)
300
* @return {Number} The computed value for the current animation frame
302
backBoth: function (t, b, c, d, s) {
303
if (typeof s === 'undefined') {
307
if ((t /= d/2 ) < 1) {
308
return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
310
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
314
* Bounce off of start.
316
* @param {Number} t Time value used to compute current value
317
* @param {Number} b Starting value
318
* @param {Number} c Delta between start and end values
319
* @param {Number} d Total length of animation
320
* @return {Number} The computed value for the current animation frame
322
bounceIn: function (t, b, c, d) {
323
return c - Y.Easing.bounceOut(d-t, 0, c, d) + b;
329
* @param {Number} t Time value used to compute current value
330
* @param {Number} b Starting value
331
* @param {Number} c Delta between start and end values
332
* @param {Number} d Total length of animation
333
* @return {Number} The computed value for the current animation frame
335
bounceOut: function (t, b, c, d) {
336
if ((t/=d) < (1/2.75)) {
337
return c*(7.5625*t*t) + b;
338
} else if (t < (2/2.75)) {
339
return c*(7.5625*(t-=(1.5/2.75))*t + 0.75) + b;
340
} else if (t < (2.5/2.75)) {
341
return c*(7.5625*(t-=(2.25/2.75))*t + 0.9375) + b;
343
return c*(7.5625*(t-=(2.625/2.75))*t + 0.984375) + b;
347
* Bounces off start and end.
349
* @param {Number} t Time value used to compute current value
350
* @param {Number} b Starting value
351
* @param {Number} c Delta between start and end values
352
* @param {Number} d Total length of animation
353
* @return {Number} The computed value for the current animation frame
355
bounceBoth: function (t, b, c, d) {
357
return Y.Easing.bounceIn(t * 2, 0, c, d) * 0.5 + b;
359
return Y.Easing.bounceOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
366
}, '3.9.1', {"requires": ["anim-base"]});