2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
8 YUI.add('anim-easing', function(Y) {
11 TERMS OF USE - EASING EQUATIONS
12 Open source under the BSD License.
13 Copyright 2001 Robert Penner All rights reserved.
15 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
17 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
18 * 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.
19 * 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.
21 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.
25 * The easing module provides methods for customizing
26 * how an animation behaves during each run.
29 * @submodule anim-easing
35 * Uniform speed between points.
38 * @param {Number} t Time value used to compute current value
39 * @param {Number} b Starting value
40 * @param {Number} c Delta between start and end values
41 * @param {Number} d Total length of animation
42 * @return {Number} The computed value for the current animation frame
44 easeNone: function (t, b, c, d) {
49 * Begins slowly and accelerates towards end. (quadratic)
51 * @param {Number} t Time value used to compute current value
52 * @param {Number} b Starting value
53 * @param {Number} c Delta between start and end values
54 * @param {Number} d Total length of animation
55 * @return {Number} The computed value for the current animation frame
57 easeIn: function (t, b, c, d) {
58 return c*(t/=d)*t + b;
62 * Begins quickly and decelerates towards end. (quadratic)
64 * @param {Number} t Time value used to compute current value
65 * @param {Number} b Starting value
66 * @param {Number} c Delta between start and end values
67 * @param {Number} d Total length of animation
68 * @return {Number} The computed value for the current animation frame
70 easeOut: function (t, b, c, d) {
71 return -c *(t/=d)*(t-2) + b;
75 * Begins slowly and decelerates towards end. (quadratic)
77 * @param {Number} t Time value used to compute current value
78 * @param {Number} b Starting value
79 * @param {Number} c Delta between start and end values
80 * @param {Number} d Total length of animation
81 * @return {Number} The computed value for the current animation frame
83 easeBoth: function (t, b, c, d) {
88 return -c/2 * ((--t)*(t-2) - 1) + b;
92 * Begins slowly and accelerates towards end. (quartic)
93 * @method easeInStrong
94 * @param {Number} t Time value used to compute current value
95 * @param {Number} b Starting value
96 * @param {Number} c Delta between start and end values
97 * @param {Number} d Total length of animation
98 * @return {Number} The computed value for the current animation frame
100 easeInStrong: function (t, b, c, d) {
101 return c*(t/=d)*t*t*t + b;
105 * Begins quickly and decelerates towards end. (quartic)
106 * @method easeOutStrong
107 * @param {Number} t Time value used to compute current value
108 * @param {Number} b Starting value
109 * @param {Number} c Delta between start and end values
110 * @param {Number} d Total length of animation
111 * @return {Number} The computed value for the current animation frame
113 easeOutStrong: function (t, b, c, d) {
114 return -c * ((t=t/d-1)*t*t*t - 1) + b;
118 * Begins slowly and decelerates towards end. (quartic)
119 * @method easeBothStrong
120 * @param {Number} t Time value used to compute current value
121 * @param {Number} b Starting value
122 * @param {Number} c Delta between start and end values
123 * @param {Number} d Total length of animation
124 * @return {Number} The computed value for the current animation frame
126 easeBothStrong: function (t, b, c, d) {
128 return c/2*t*t*t*t + b;
131 return -c/2 * ((t-=2)*t*t*t - 2) + b;
135 * Snap in elastic effect.
137 * @param {Number} t Time value used to compute current value
138 * @param {Number} b Starting value
139 * @param {Number} c Delta between start and end values
140 * @param {Number} d Total length of animation
141 * @param {Number} a Amplitude (optional)
142 * @param {Number} p Period (optional)
143 * @return {Number} The computed value for the current animation frame
146 elasticIn: function (t, b, c, d, a, p) {
151 if ( (t /= d) === 1 ) {
158 if (!a || a < Math.abs(c)) {
163 s = p/(2*Math.PI) * Math.asin (c/a);
166 return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
170 * Snap out elastic effect.
172 * @param {Number} t Time value used to compute current value
173 * @param {Number} b Starting value
174 * @param {Number} c Delta between start and end values
175 * @param {Number} d Total length of animation
176 * @param {Number} a Amplitude (optional)
177 * @param {Number} p Period (optional)
178 * @return {Number} The computed value for the current animation frame
180 elasticOut: function (t, b, c, d, a, p) {
185 if ( (t /= d) === 1 ) {
192 if (!a || a < Math.abs(c)) {
197 s = p/(2*Math.PI) * Math.asin (c/a);
200 return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
204 * Snap both elastic effect.
205 * @method elasticBoth
206 * @param {Number} t Time value used to compute current value
207 * @param {Number} b Starting value
208 * @param {Number} c Delta between start and end values
209 * @param {Number} d Total length of animation
210 * @param {Number} a Amplitude (optional)
211 * @param {Number} p Period (optional)
212 * @return {Number} The computed value for the current animation frame
214 elasticBoth: function (t, b, c, d, a, p) {
220 if ( (t /= d/2) === 2 ) {
228 if ( !a || a < Math.abs(c) ) {
233 s = p/(2*Math.PI) * Math.asin (c/a);
237 return -0.5*(a*Math.pow(2,10*(t-=1)) *
238 Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
240 return a*Math.pow(2,-10*(t-=1)) *
241 Math.sin( (t*d-s)*(2*Math.PI)/p )*0.5 + c + b;
246 * Backtracks slightly, then reverses direction and moves to end.
248 * @param {Number} t Time value used to compute current value
249 * @param {Number} b Starting value
250 * @param {Number} c Delta between start and end values
251 * @param {Number} d Total length of animation
252 * @param {Number} s Overshoot (optional)
253 * @return {Number} The computed value for the current animation frame
255 backIn: function (t, b, c, d, s) {
256 if (s === undefined) {
262 return c*(t/=d)*t*((s+1)*t - s) + b;
266 * Overshoots end, then reverses and comes back to end.
268 * @param {Number} t Time value used to compute current value
269 * @param {Number} b Starting value
270 * @param {Number} c Delta between start and end values
271 * @param {Number} d Total length of animation
272 * @param {Number} s Overshoot (optional)
273 * @return {Number} The computed value for the current animation frame
275 backOut: function (t, b, c, d, s) {
276 if (typeof s === 'undefined') {
279 return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
283 * Backtracks slightly, then reverses direction, overshoots end,
284 * then reverses and comes back to end.
286 * @param {Number} t Time value used to compute current value
287 * @param {Number} b Starting value
288 * @param {Number} c Delta between start and end values
289 * @param {Number} d Total length of animation
290 * @param {Number} s Overshoot (optional)
291 * @return {Number} The computed value for the current animation frame
293 backBoth: function (t, b, c, d, s) {
294 if (typeof s === 'undefined') {
298 if ((t /= d/2 ) < 1) {
299 return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
301 return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
305 * Bounce off of start.
307 * @param {Number} t Time value used to compute current value
308 * @param {Number} b Starting value
309 * @param {Number} c Delta between start and end values
310 * @param {Number} d Total length of animation
311 * @return {Number} The computed value for the current animation frame
313 bounceIn: function (t, b, c, d) {
314 return c - Y.Easing.bounceOut(d-t, 0, c, d) + b;
320 * @param {Number} t Time value used to compute current value
321 * @param {Number} b Starting value
322 * @param {Number} c Delta between start and end values
323 * @param {Number} d Total length of animation
324 * @return {Number} The computed value for the current animation frame
326 bounceOut: function (t, b, c, d) {
327 if ((t/=d) < (1/2.75)) {
328 return c*(7.5625*t*t) + b;
329 } else if (t < (2/2.75)) {
330 return c*(7.5625*(t-=(1.5/2.75))*t + 0.75) + b;
331 } else if (t < (2.5/2.75)) {
332 return c*(7.5625*(t-=(2.25/2.75))*t + 0.9375) + b;
334 return c*(7.5625*(t-=(2.625/2.75))*t + 0.984375) + b;
338 * Bounces off start and end.
340 * @param {Number} t Time value used to compute current value
341 * @param {Number} b Starting value
342 * @param {Number} c Delta between start and end values
343 * @param {Number} d Total length of animation
344 * @return {Number} The computed value for the current animation frame
346 bounceBoth: function (t, b, c, d) {
348 return Y.Easing.bounceIn(t * 2, 0, c, d) * 0.5 + b;
350 return Y.Easing.bounceOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
357 }, '3.3.0' ,{requires:['anim-base']});