|
602
|
1 |
YUI.add('anim-easing', function (Y, NAME) { |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
TERMS OF USE - EASING EQUATIONS |
|
|
5 |
Open source under the BSD License. |
|
|
6 |
Copyright 2001 Robert Penner All rights reserved. |
|
|
7 |
|
|
|
8 |
Redistribution and use in source and binary forms, with or without modification, |
|
|
9 |
are permitted provided that the following conditions are met: |
|
|
10 |
|
|
|
11 |
* Redistributions of source code must retain the above copyright notice, this |
|
|
12 |
list of conditions and the following disclaimer. |
|
|
13 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
|
14 |
this list of conditions and the following disclaimer in the documentation |
|
|
15 |
and/or other materials provided with the distribution. |
|
|
16 |
* Neither the name of the author nor the names of contributors may be used to |
|
|
17 |
endorse or promote products derived from this software without specific prior |
|
|
18 |
written permission. |
|
|
19 |
|
|
|
20 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
|
21 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
|
22 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
|
23 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
|
24 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
|
25 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
|
26 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
|
27 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
|
|
28 |
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
|
|
29 |
OF THE POSSIBILITY OF SUCH DAMAGE. |
|
|
30 |
*/ |
|
|
31 |
|
|
|
32 |
/** |
|
|
33 |
* The easing module provides methods for customizing |
|
|
34 |
* how an animation behaves during each run. |
|
|
35 |
* @class Easing |
|
|
36 |
* @module anim |
|
|
37 |
* @submodule anim-easing |
|
|
38 |
*/ |
|
|
39 |
|
|
|
40 |
var Easing = { |
|
|
41 |
|
|
|
42 |
/** |
|
|
43 |
* Uniform speed between points. |
|
|
44 |
* @for Easing |
|
|
45 |
* @method easeNone |
|
|
46 |
* @param {Number} t Time value used to compute current value |
|
|
47 |
* @param {Number} b Starting value |
|
|
48 |
* @param {Number} c Delta between start and end values |
|
|
49 |
* @param {Number} d Total length of animation |
|
|
50 |
* @return {Number} The computed value for the current animation frame |
|
|
51 |
*/ |
|
|
52 |
easeNone: function (t, b, c, d) { |
|
|
53 |
return c*t/d + b; |
|
|
54 |
}, |
|
|
55 |
|
|
|
56 |
/** |
|
|
57 |
* Begins slowly and accelerates towards end. (quadratic) |
|
|
58 |
* @method easeIn |
|
|
59 |
* @param {Number} t Time value used to compute current value |
|
|
60 |
* @param {Number} b Starting value |
|
|
61 |
* @param {Number} c Delta between start and end values |
|
|
62 |
* @param {Number} d Total length of animation |
|
|
63 |
* @return {Number} The computed value for the current animation frame |
|
|
64 |
*/ |
|
|
65 |
easeIn: function (t, b, c, d) { |
|
|
66 |
return c*(t/=d)*t + b; |
|
|
67 |
}, |
|
|
68 |
|
|
|
69 |
/** |
|
|
70 |
* Begins quickly and decelerates towards end. (quadratic) |
|
|
71 |
* @method easeOut |
|
|
72 |
* @param {Number} t Time value used to compute current value |
|
|
73 |
* @param {Number} b Starting value |
|
|
74 |
* @param {Number} c Delta between start and end values |
|
|
75 |
* @param {Number} d Total length of animation |
|
|
76 |
* @return {Number} The computed value for the current animation frame |
|
|
77 |
*/ |
|
|
78 |
easeOut: function (t, b, c, d) { |
|
|
79 |
return -c *(t/=d)*(t-2) + b; |
|
|
80 |
}, |
|
|
81 |
|
|
|
82 |
/** |
|
|
83 |
* Begins slowly and decelerates towards end. (quadratic) |
|
|
84 |
* @method easeBoth |
|
|
85 |
* @param {Number} t Time value used to compute current value |
|
|
86 |
* @param {Number} b Starting value |
|
|
87 |
* @param {Number} c Delta between start and end values |
|
|
88 |
* @param {Number} d Total length of animation |
|
|
89 |
* @return {Number} The computed value for the current animation frame |
|
|
90 |
*/ |
|
|
91 |
easeBoth: function (t, b, c, d) { |
|
|
92 |
if ((t /= d/2) < 1) { |
|
|
93 |
return c/2*t*t + b; |
|
|
94 |
} |
|
|
95 |
|
|
|
96 |
return -c/2 * ((--t)*(t-2) - 1) + b; |
|
|
97 |
}, |
|
|
98 |
|
|
|
99 |
/** |
|
|
100 |
* Begins slowly and accelerates towards end. (quartic) |
|
|
101 |
* @method easeInStrong |
|
|
102 |
* @param {Number} t Time value used to compute current value |
|
|
103 |
* @param {Number} b Starting value |
|
|
104 |
* @param {Number} c Delta between start and end values |
|
|
105 |
* @param {Number} d Total length of animation |
|
|
106 |
* @return {Number} The computed value for the current animation frame |
|
|
107 |
*/ |
|
|
108 |
easeInStrong: function (t, b, c, d) { |
|
|
109 |
return c*(t/=d)*t*t*t + b; |
|
|
110 |
}, |
|
|
111 |
|
|
|
112 |
/** |
|
|
113 |
* Begins quickly and decelerates towards end. (quartic) |
|
|
114 |
* @method easeOutStrong |
|
|
115 |
* @param {Number} t Time value used to compute current value |
|
|
116 |
* @param {Number} b Starting value |
|
|
117 |
* @param {Number} c Delta between start and end values |
|
|
118 |
* @param {Number} d Total length of animation |
|
|
119 |
* @return {Number} The computed value for the current animation frame |
|
|
120 |
*/ |
|
|
121 |
easeOutStrong: function (t, b, c, d) { |
|
|
122 |
return -c * ((t=t/d-1)*t*t*t - 1) + b; |
|
|
123 |
}, |
|
|
124 |
|
|
|
125 |
/** |
|
|
126 |
* Begins slowly and decelerates towards end. (quartic) |
|
|
127 |
* @method easeBothStrong |
|
|
128 |
* @param {Number} t Time value used to compute current value |
|
|
129 |
* @param {Number} b Starting value |
|
|
130 |
* @param {Number} c Delta between start and end values |
|
|
131 |
* @param {Number} d Total length of animation |
|
|
132 |
* @return {Number} The computed value for the current animation frame |
|
|
133 |
*/ |
|
|
134 |
easeBothStrong: function (t, b, c, d) { |
|
|
135 |
if ((t /= d/2) < 1) { |
|
|
136 |
return c/2*t*t*t*t + b; |
|
|
137 |
} |
|
|
138 |
|
|
|
139 |
return -c/2 * ((t-=2)*t*t*t - 2) + b; |
|
|
140 |
}, |
|
|
141 |
|
|
|
142 |
/** |
|
|
143 |
* Snap in elastic effect. |
|
|
144 |
* @method elasticIn |
|
|
145 |
* @param {Number} t Time value used to compute current value |
|
|
146 |
* @param {Number} b Starting value |
|
|
147 |
* @param {Number} c Delta between start and end values |
|
|
148 |
* @param {Number} d Total length of animation |
|
|
149 |
* @param {Number} a Amplitude (optional) |
|
|
150 |
* @param {Number} p Period (optional) |
|
|
151 |
* @return {Number} The computed value for the current animation frame |
|
|
152 |
*/ |
|
|
153 |
|
|
|
154 |
elasticIn: function (t, b, c, d, a, p) { |
|
|
155 |
var s; |
|
|
156 |
if (t === 0) { |
|
|
157 |
return b; |
|
|
158 |
} |
|
|
159 |
if ( (t /= d) === 1 ) { |
|
|
160 |
return b+c; |
|
|
161 |
} |
|
|
162 |
if (!p) { |
|
|
163 |
p = d* 0.3; |
|
|
164 |
} |
|
|
165 |
|
|
|
166 |
if (!a || a < Math.abs(c)) { |
|
|
167 |
a = c; |
|
|
168 |
s = p/4; |
|
|
169 |
} |
|
|
170 |
else { |
|
|
171 |
s = p/(2*Math.PI) * Math.asin (c/a); |
|
|
172 |
} |
|
|
173 |
|
|
|
174 |
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; |
|
|
175 |
}, |
|
|
176 |
|
|
|
177 |
/** |
|
|
178 |
* Snap out elastic effect. |
|
|
179 |
* @method elasticOut |
|
|
180 |
* @param {Number} t Time value used to compute current value |
|
|
181 |
* @param {Number} b Starting value |
|
|
182 |
* @param {Number} c Delta between start and end values |
|
|
183 |
* @param {Number} d Total length of animation |
|
|
184 |
* @param {Number} a Amplitude (optional) |
|
|
185 |
* @param {Number} p Period (optional) |
|
|
186 |
* @return {Number} The computed value for the current animation frame |
|
|
187 |
*/ |
|
|
188 |
elasticOut: function (t, b, c, d, a, p) { |
|
|
189 |
var s; |
|
|
190 |
if (t === 0) { |
|
|
191 |
return b; |
|
|
192 |
} |
|
|
193 |
if ( (t /= d) === 1 ) { |
|
|
194 |
return b+c; |
|
|
195 |
} |
|
|
196 |
if (!p) { |
|
|
197 |
p=d * 0.3; |
|
|
198 |
} |
|
|
199 |
|
|
|
200 |
if (!a || a < Math.abs(c)) { |
|
|
201 |
a = c; |
|
|
202 |
s = p / 4; |
|
|
203 |
} |
|
|
204 |
else { |
|
|
205 |
s = p/(2*Math.PI) * Math.asin (c/a); |
|
|
206 |
} |
|
|
207 |
|
|
|
208 |
return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b; |
|
|
209 |
}, |
|
|
210 |
|
|
|
211 |
/** |
|
|
212 |
* Snap both elastic effect. |
|
|
213 |
* @method elasticBoth |
|
|
214 |
* @param {Number} t Time value used to compute current value |
|
|
215 |
* @param {Number} b Starting value |
|
|
216 |
* @param {Number} c Delta between start and end values |
|
|
217 |
* @param {Number} d Total length of animation |
|
|
218 |
* @param {Number} a Amplitude (optional) |
|
|
219 |
* @param {Number} p Period (optional) |
|
|
220 |
* @return {Number} The computed value for the current animation frame |
|
|
221 |
*/ |
|
|
222 |
elasticBoth: function (t, b, c, d, a, p) { |
|
|
223 |
var s; |
|
|
224 |
if (t === 0) { |
|
|
225 |
return b; |
|
|
226 |
} |
|
|
227 |
|
|
|
228 |
if ( (t /= d/2) === 2 ) { |
|
|
229 |
return b+c; |
|
|
230 |
} |
|
|
231 |
|
|
|
232 |
if (!p) { |
|
|
233 |
p = d*(0.3*1.5); |
|
|
234 |
} |
|
|
235 |
|
|
|
236 |
if ( !a || a < Math.abs(c) ) { |
|
|
237 |
a = c; |
|
|
238 |
s = p/4; |
|
|
239 |
} |
|
|
240 |
else { |
|
|
241 |
s = p/(2*Math.PI) * Math.asin (c/a); |
|
|
242 |
} |
|
|
243 |
|
|
|
244 |
if (t < 1) { |
|
|
245 |
return -0.5*(a*Math.pow(2,10*(t-=1)) * |
|
|
246 |
Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; |
|
|
247 |
} |
|
|
248 |
return a*Math.pow(2,-10*(t-=1)) * |
|
|
249 |
Math.sin( (t*d-s)*(2*Math.PI)/p )*0.5 + c + b; |
|
|
250 |
}, |
|
|
251 |
|
|
|
252 |
|
|
|
253 |
/** |
|
|
254 |
* Backtracks slightly, then reverses direction and moves to end. |
|
|
255 |
* @method backIn |
|
|
256 |
* @param {Number} t Time value used to compute current value |
|
|
257 |
* @param {Number} b Starting value |
|
|
258 |
* @param {Number} c Delta between start and end values |
|
|
259 |
* @param {Number} d Total length of animation |
|
|
260 |
* @param {Number} s Overshoot (optional) |
|
|
261 |
* @return {Number} The computed value for the current animation frame |
|
|
262 |
*/ |
|
|
263 |
backIn: function (t, b, c, d, s) { |
|
|
264 |
if (s === undefined) { |
|
|
265 |
s = 1.70158; |
|
|
266 |
} |
|
|
267 |
if (t === d) { |
|
|
268 |
t -= 0.001; |
|
|
269 |
} |
|
|
270 |
return c*(t/=d)*t*((s+1)*t - s) + b; |
|
|
271 |
}, |
|
|
272 |
|
|
|
273 |
/** |
|
|
274 |
* Overshoots end, then reverses and comes back to end. |
|
|
275 |
* @method backOut |
|
|
276 |
* @param {Number} t Time value used to compute current value |
|
|
277 |
* @param {Number} b Starting value |
|
|
278 |
* @param {Number} c Delta between start and end values |
|
|
279 |
* @param {Number} d Total length of animation |
|
|
280 |
* @param {Number} s Overshoot (optional) |
|
|
281 |
* @return {Number} The computed value for the current animation frame |
|
|
282 |
*/ |
|
|
283 |
backOut: function (t, b, c, d, s) { |
|
|
284 |
if (typeof s === 'undefined') { |
|
|
285 |
s = 1.70158; |
|
|
286 |
} |
|
|
287 |
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; |
|
|
288 |
}, |
|
|
289 |
|
|
|
290 |
/** |
|
|
291 |
* Backtracks slightly, then reverses direction, overshoots end, |
|
|
292 |
* then reverses and comes back to end. |
|
|
293 |
* @method backBoth |
|
|
294 |
* @param {Number} t Time value used to compute current value |
|
|
295 |
* @param {Number} b Starting value |
|
|
296 |
* @param {Number} c Delta between start and end values |
|
|
297 |
* @param {Number} d Total length of animation |
|
|
298 |
* @param {Number} s Overshoot (optional) |
|
|
299 |
* @return {Number} The computed value for the current animation frame |
|
|
300 |
*/ |
|
|
301 |
backBoth: function (t, b, c, d, s) { |
|
|
302 |
if (typeof s === 'undefined') { |
|
|
303 |
s = 1.70158; |
|
|
304 |
} |
|
|
305 |
|
|
|
306 |
if ((t /= d/2 ) < 1) { |
|
|
307 |
return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; |
|
|
308 |
} |
|
|
309 |
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; |
|
|
310 |
}, |
|
|
311 |
|
|
|
312 |
/** |
|
|
313 |
* Bounce off of start. |
|
|
314 |
* @method bounceIn |
|
|
315 |
* @param {Number} t Time value used to compute current value |
|
|
316 |
* @param {Number} b Starting value |
|
|
317 |
* @param {Number} c Delta between start and end values |
|
|
318 |
* @param {Number} d Total length of animation |
|
|
319 |
* @return {Number} The computed value for the current animation frame |
|
|
320 |
*/ |
|
|
321 |
bounceIn: function (t, b, c, d) { |
|
|
322 |
return c - Y.Easing.bounceOut(d-t, 0, c, d) + b; |
|
|
323 |
}, |
|
|
324 |
|
|
|
325 |
/** |
|
|
326 |
* Bounces off end. |
|
|
327 |
* @method bounceOut |
|
|
328 |
* @param {Number} t Time value used to compute current value |
|
|
329 |
* @param {Number} b Starting value |
|
|
330 |
* @param {Number} c Delta between start and end values |
|
|
331 |
* @param {Number} d Total length of animation |
|
|
332 |
* @return {Number} The computed value for the current animation frame |
|
|
333 |
*/ |
|
|
334 |
bounceOut: function (t, b, c, d) { |
|
|
335 |
if ((t/=d) < (1/2.75)) { |
|
|
336 |
return c*(7.5625*t*t) + b; |
|
|
337 |
} else if (t < (2/2.75)) { |
|
|
338 |
return c*(7.5625*(t-=(1.5/2.75))*t + 0.75) + b; |
|
|
339 |
} else if (t < (2.5/2.75)) { |
|
|
340 |
return c*(7.5625*(t-=(2.25/2.75))*t + 0.9375) + b; |
|
|
341 |
} |
|
|
342 |
return c*(7.5625*(t-=(2.625/2.75))*t + 0.984375) + b; |
|
|
343 |
}, |
|
|
344 |
|
|
|
345 |
/** |
|
|
346 |
* Bounces off start and end. |
|
|
347 |
* @method bounceBoth |
|
|
348 |
* @param {Number} t Time value used to compute current value |
|
|
349 |
* @param {Number} b Starting value |
|
|
350 |
* @param {Number} c Delta between start and end values |
|
|
351 |
* @param {Number} d Total length of animation |
|
|
352 |
* @return {Number} The computed value for the current animation frame |
|
|
353 |
*/ |
|
|
354 |
bounceBoth: function (t, b, c, d) { |
|
|
355 |
if (t < d/2) { |
|
|
356 |
return Y.Easing.bounceIn(t * 2, 0, c, d) * 0.5 + b; |
|
|
357 |
} |
|
|
358 |
return Y.Easing.bounceOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b; |
|
|
359 |
} |
|
|
360 |
}; |
|
|
361 |
|
|
|
362 |
Y.Easing = Easing; |
|
|
363 |
|
|
|
364 |
|
|
|
365 |
}, '@VERSION@', {"requires": ["anim-base"]}); |