2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('anim-easing', function (Y, NAME) {
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,
16 are permitted provided that the following conditions are met:
18 * Redistributions of source code must retain the above copyright notice, this
19 list of conditions and the following disclaimer.
20 * Redistributions in binary form must reproduce the above copyright notice,
21 this list of conditions and the following disclaimer in the documentation
22 and/or other materials provided with the distribution.
23 * Neither the name of the author nor the names of contributors may be used to
24 endorse or promote products derived from this software without specific prior
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
28 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
31 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
34 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
35 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
36 OF THE POSSIBILITY OF SUCH DAMAGE.
40 * The easing module provides methods for customizing
41 * how an animation behaves during each run.
44 * @submodule anim-easing
50 * Uniform speed between points.
53 * @param {Number} t Time value used to compute current value
54 * @param {Number} b Starting value
55 * @param {Number} c Delta between start and end values
56 * @param {Number} d Total length of animation
57 * @return {Number} The computed value for the current animation frame
59 easeNone: function (t, b, c, d) {
64 * Begins slowly and accelerates towards end. (quadratic)
66 * @param {Number} t Time value used to compute current value
67 * @param {Number} b Starting value
68 * @param {Number} c Delta between start and end values
69 * @param {Number} d Total length of animation
70 * @return {Number} The computed value for the current animation frame
72 easeIn: function (t, b, c, d) {
73 return c*(t/=d)*t + b;
77 * Begins quickly and decelerates towards end. (quadratic)
79 * @param {Number} t Time value used to compute current value
80 * @param {Number} b Starting value
81 * @param {Number} c Delta between start and end values
82 * @param {Number} d Total length of animation
83 * @return {Number} The computed value for the current animation frame
85 easeOut: function (t, b, c, d) {
86 return -c *(t/=d)*(t-2) + b;
90 * Begins slowly and decelerates towards end. (quadratic)
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 easeBoth: function (t, b, c, d) {
103 return -c/2 * ((--t)*(t-2) - 1) + b;
107 * Begins slowly and accelerates towards end. (quartic)
108 * @method easeInStrong
109 * @param {Number} t Time value used to compute current value
110 * @param {Number} b Starting value
111 * @param {Number} c Delta between start and end values
112 * @param {Number} d Total length of animation
113 * @return {Number} The computed value for the current animation frame
115 easeInStrong: function (t, b, c, d) {
116 return c*(t/=d)*t*t*t + b;
120 * Begins quickly and decelerates towards end. (quartic)
121 * @method easeOutStrong
122 * @param {Number} t Time value used to compute current value
123 * @param {Number} b Starting value
124 * @param {Number} c Delta between start and end values
125 * @param {Number} d Total length of animation
126 * @return {Number} The computed value for the current animation frame
128 easeOutStrong: function (t, b, c, d) {
129 return -c * ((t=t/d-1)*t*t*t - 1) + b;
133 * Begins slowly and decelerates towards end. (quartic)
134 * @method easeBothStrong
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 * @return {Number} The computed value for the current animation frame
141 easeBothStrong: function (t, b, c, d) {
142 if ((t /= d/2) < 1) {
143 return c/2*t*t*t*t + b;
146 return -c/2 * ((t-=2)*t*t*t - 2) + b;
150 * Snap in elastic effect.
152 * @param {Number} t Time value used to compute current value
153 * @param {Number} b Starting value
154 * @param {Number} c Delta between start and end values
155 * @param {Number} d Total length of animation
156 * @param {Number} a Amplitude (optional)
157 * @param {Number} p Period (optional)
158 * @return {Number} The computed value for the current animation frame
161 elasticIn: function (t, b, c, d, a, p) {
166 if ( (t /= d) === 1 ) {
173 if (!a || a < Math.abs(c)) {
178 s = p/(2*Math.PI) * Math.asin (c/a);
181 return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
185 * Snap out elastic effect.
187 * @param {Number} t Time value used to compute current value
188 * @param {Number} b Starting value
189 * @param {Number} c Delta between start and end values
190 * @param {Number} d Total length of animation
191 * @param {Number} a Amplitude (optional)
192 * @param {Number} p Period (optional)
193 * @return {Number} The computed value for the current animation frame
195 elasticOut: function (t, b, c, d, a, p) {
200 if ( (t /= d) === 1 ) {
207 if (!a || a < Math.abs(c)) {
212 s = p/(2*Math.PI) * Math.asin (c/a);
215 return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
219 * Snap both elastic effect.
220 * @method elasticBoth
221 * @param {Number} t Time value used to compute current value
222 * @param {Number} b Starting value
223 * @param {Number} c Delta between start and end values
224 * @param {Number} d Total length of animation
225 * @param {Number} a Amplitude (optional)
226 * @param {Number} p Period (optional)
227 * @return {Number} The computed value for the current animation frame
229 elasticBoth: function (t, b, c, d, a, p) {
235 if ( (t /= d/2) === 2 ) {
243 if ( !a || a < Math.abs(c) ) {
248 s = p/(2*Math.PI) * Math.asin (c/a);
252 return -0.5*(a*Math.pow(2,10*(t-=1)) *
253 Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
255 return a*Math.pow(2,-10*(t-=1)) *
256 Math.sin( (t*d-s)*(2*Math.PI)/p )*0.5 + c + b;
261 * Backtracks slightly, then reverses direction and moves to end.
263 * @param {Number} t Time value used to compute current value
264 * @param {Number} b Starting value
265 * @param {Number} c Delta between start and end values
266 * @param {Number} d Total length of animation
267 * @param {Number} s Overshoot (optional)
268 * @return {Number} The computed value for the current animation frame
270 backIn: function (t, b, c, d, s) {
271 if (s === undefined) {
277 return c*(t/=d)*t*((s+1)*t - s) + b;
281 * Overshoots end, then reverses and comes back to end.
283 * @param {Number} t Time value used to compute current value
284 * @param {Number} b Starting value
285 * @param {Number} c Delta between start and end values
286 * @param {Number} d Total length of animation
287 * @param {Number} s Overshoot (optional)
288 * @return {Number} The computed value for the current animation frame
290 backOut: function (t, b, c, d, s) {
291 if (typeof s === 'undefined') {
294 return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
298 * Backtracks slightly, then reverses direction, overshoots end,
299 * then reverses and comes back to end.
301 * @param {Number} t Time value used to compute current value
302 * @param {Number} b Starting value
303 * @param {Number} c Delta between start and end values
304 * @param {Number} d Total length of animation
305 * @param {Number} s Overshoot (optional)
306 * @return {Number} The computed value for the current animation frame
308 backBoth: function (t, b, c, d, s) {
309 if (typeof s === 'undefined') {
313 if ((t /= d/2 ) < 1) {
314 return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
316 return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
320 * Bounce off of start.
322 * @param {Number} t Time value used to compute current value
323 * @param {Number} b Starting value
324 * @param {Number} c Delta between start and end values
325 * @param {Number} d Total length of animation
326 * @return {Number} The computed value for the current animation frame
328 bounceIn: function (t, b, c, d) {
329 return c - Y.Easing.bounceOut(d-t, 0, c, d) + b;
335 * @param {Number} t Time value used to compute current value
336 * @param {Number} b Starting value
337 * @param {Number} c Delta between start and end values
338 * @param {Number} d Total length of animation
339 * @return {Number} The computed value for the current animation frame
341 bounceOut: function (t, b, c, d) {
342 if ((t/=d) < (1/2.75)) {
343 return c*(7.5625*t*t) + b;
344 } else if (t < (2/2.75)) {
345 return c*(7.5625*(t-=(1.5/2.75))*t + 0.75) + b;
346 } else if (t < (2.5/2.75)) {
347 return c*(7.5625*(t-=(2.25/2.75))*t + 0.9375) + b;
349 return c*(7.5625*(t-=(2.625/2.75))*t + 0.984375) + b;
353 * Bounces off start and end.
355 * @param {Number} t Time value used to compute current value
356 * @param {Number} b Starting value
357 * @param {Number} c Delta between start and end values
358 * @param {Number} d Total length of animation
359 * @return {Number} The computed value for the current animation frame
361 bounceBoth: function (t, b, c, d) {
363 return Y.Easing.bounceIn(t * 2, 0, c, d) * 0.5 + b;
365 return Y.Easing.bounceOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
372 }, '3.13.0', {"requires": ["anim-base"]});