]>
Commit | Line | Data |
---|---|---|
2f01fe57 AD |
1 | /* |
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. | |
3 | Available via Academic Free License >= 2.1 OR the modified BSD license. | |
4 | see: http://dojotoolkit.org/license for details | |
5 | */ | |
6 | ||
7 | ||
a089699c AD |
8 | if(!dojo._hasResource["dojo.fx.easing"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. |
9 | dojo._hasResource["dojo.fx.easing"] = true; | |
2f01fe57 | 10 | dojo.provide("dojo.fx.easing"); |
a089699c AD |
11 | |
12 | dojo.fx.easing = { | |
13 | // summary: | |
14 | // Collection of easing functions to use beyond the default | |
15 | // `dojo._defaultEasing` function. | |
16 | // | |
17 | // description: | |
18 | // | |
19 | // Easing functions are used to manipulate the iteration through | |
20 | // an `dojo.Animation`s _Line. _Line being the properties of an Animation, | |
21 | // and the easing function progresses through that Line determing | |
22 | // how quickly (or slowly) it should go. Or more accurately: modify | |
23 | // the value of the _Line based on the percentage of animation completed. | |
24 | // | |
25 | // All functions follow a simple naming convention of "ease type" + "when". | |
26 | // If the name of the function ends in Out, the easing described appears | |
27 | // towards the end of the animation. "In" means during the beginning, | |
28 | // and InOut means both ranges of the Animation will applied, both | |
29 | // beginning and end. | |
30 | // | |
31 | // One does not call the easing function directly, it must be passed to | |
32 | // the `easing` property of an animation. | |
33 | // | |
34 | // example: | |
35 | // | dojo.require("dojo.fx.easing"); | |
36 | // | var anim = dojo.fadeOut({ | |
37 | // | node: 'node', | |
38 | // | duration: 2000, | |
39 | // | // note there is no () | |
40 | // | easing: dojo.fx.easing.quadIn | |
41 | // | }).play(); | |
42 | // | |
43 | ||
44 | linear: function(/* Decimal? */n){ | |
45 | // summary: A linear easing function | |
46 | return n; | |
47 | }, | |
48 | ||
49 | quadIn: function(/* Decimal? */n){ | |
50 | return Math.pow(n, 2); | |
51 | }, | |
52 | ||
53 | quadOut: function(/* Decimal? */n){ | |
54 | return n * (n - 2) * -1; | |
55 | }, | |
56 | ||
57 | quadInOut: function(/* Decimal? */n){ | |
58 | n = n * 2; | |
59 | if(n < 1){ return Math.pow(n, 2) / 2; } | |
60 | return -1 * ((--n) * (n - 2) - 1) / 2; | |
61 | }, | |
62 | ||
63 | cubicIn: function(/* Decimal? */n){ | |
64 | return Math.pow(n, 3); | |
65 | }, | |
66 | ||
67 | cubicOut: function(/* Decimal? */n){ | |
68 | return Math.pow(n - 1, 3) + 1; | |
69 | }, | |
70 | ||
71 | cubicInOut: function(/* Decimal? */n){ | |
72 | n = n * 2; | |
73 | if(n < 1){ return Math.pow(n, 3) / 2; } | |
74 | n -= 2; | |
75 | return (Math.pow(n, 3) + 2) / 2; | |
76 | }, | |
77 | ||
78 | quartIn: function(/* Decimal? */n){ | |
79 | return Math.pow(n, 4); | |
80 | }, | |
81 | ||
82 | quartOut: function(/* Decimal? */n){ | |
83 | return -1 * (Math.pow(n - 1, 4) - 1); | |
84 | }, | |
85 | ||
86 | quartInOut: function(/* Decimal? */n){ | |
87 | n = n * 2; | |
88 | if(n < 1){ return Math.pow(n, 4) / 2; } | |
89 | n -= 2; | |
90 | return -1 / 2 * (Math.pow(n, 4) - 2); | |
91 | }, | |
92 | ||
93 | quintIn: function(/* Decimal? */n){ | |
94 | return Math.pow(n, 5); | |
95 | }, | |
96 | ||
97 | quintOut: function(/* Decimal? */n){ | |
98 | return Math.pow(n - 1, 5) + 1; | |
99 | }, | |
100 | ||
101 | quintInOut: function(/* Decimal? */n){ | |
102 | n = n * 2; | |
103 | if(n < 1){ return Math.pow(n, 5) / 2; }; | |
104 | n -= 2; | |
105 | return (Math.pow(n, 5) + 2) / 2; | |
106 | }, | |
107 | ||
108 | sineIn: function(/* Decimal? */n){ | |
109 | return -1 * Math.cos(n * (Math.PI / 2)) + 1; | |
110 | }, | |
111 | ||
112 | sineOut: function(/* Decimal? */n){ | |
113 | return Math.sin(n * (Math.PI / 2)); | |
114 | }, | |
115 | ||
116 | sineInOut: function(/* Decimal? */n){ | |
117 | return -1 * (Math.cos(Math.PI * n) - 1) / 2; | |
118 | }, | |
119 | ||
120 | expoIn: function(/* Decimal? */n){ | |
121 | return (n == 0) ? 0 : Math.pow(2, 10 * (n - 1)); | |
122 | }, | |
123 | ||
124 | expoOut: function(/* Decimal? */n){ | |
125 | return (n == 1) ? 1 : (-1 * Math.pow(2, -10 * n) + 1); | |
126 | }, | |
127 | ||
128 | expoInOut: function(/* Decimal? */n){ | |
129 | if(n == 0){ return 0; } | |
130 | if(n == 1){ return 1; } | |
131 | n = n * 2; | |
132 | if(n < 1){ return Math.pow(2, 10 * (n - 1)) / 2; } | |
133 | --n; | |
134 | return (-1 * Math.pow(2, -10 * n) + 2) / 2; | |
135 | }, | |
136 | ||
137 | circIn: function(/* Decimal? */n){ | |
138 | return -1 * (Math.sqrt(1 - Math.pow(n, 2)) - 1); | |
139 | }, | |
140 | ||
141 | circOut: function(/* Decimal? */n){ | |
142 | n = n - 1; | |
143 | return Math.sqrt(1 - Math.pow(n, 2)); | |
144 | }, | |
145 | ||
146 | circInOut: function(/* Decimal? */n){ | |
147 | n = n * 2; | |
148 | if(n < 1){ return -1 / 2 * (Math.sqrt(1 - Math.pow(n, 2)) - 1); } | |
149 | n -= 2; | |
150 | return 1 / 2 * (Math.sqrt(1 - Math.pow(n, 2)) + 1); | |
151 | }, | |
152 | ||
153 | backIn: function(/* Decimal? */n){ | |
154 | // summary: | |
155 | // An easing function that starts away from the target, | |
156 | // and quickly accelerates towards the end value. | |
157 | // | |
158 | // Use caution when the easing will cause values to become | |
159 | // negative as some properties cannot be set to negative values. | |
160 | var s = 1.70158; | |
161 | return Math.pow(n, 2) * ((s + 1) * n - s); | |
162 | }, | |
163 | ||
164 | backOut: function(/* Decimal? */n){ | |
165 | // summary: | |
166 | // An easing function that pops past the range briefly, and slowly comes back. | |
167 | // | |
168 | // description: | |
169 | // An easing function that pops past the range briefly, and slowly comes back. | |
170 | // | |
171 | // Use caution when the easing will cause values to become negative as some | |
172 | // properties cannot be set to negative values. | |
173 | ||
174 | n = n - 1; | |
175 | var s = 1.70158; | |
176 | return Math.pow(n, 2) * ((s + 1) * n + s) + 1; | |
177 | }, | |
178 | ||
179 | backInOut: function(/* Decimal? */n){ | |
180 | // summary: | |
181 | // An easing function combining the effects of `backIn` and `backOut` | |
182 | // | |
183 | // description: | |
184 | // An easing function combining the effects of `backIn` and `backOut`. | |
185 | // Use caution when the easing will cause values to become negative | |
186 | // as some properties cannot be set to negative values. | |
187 | var s = 1.70158 * 1.525; | |
188 | n = n * 2; | |
189 | if(n < 1){ return (Math.pow(n, 2) * ((s + 1) * n - s)) / 2; } | |
190 | n-=2; | |
191 | return (Math.pow(n, 2) * ((s + 1) * n + s) + 2) / 2; | |
192 | }, | |
193 | ||
194 | elasticIn: function(/* Decimal? */n){ | |
195 | // summary: | |
196 | // An easing function the elastically snaps from the start value | |
197 | // | |
198 | // description: | |
199 | // An easing function the elastically snaps from the start value | |
200 | // | |
201 | // Use caution when the elasticity will cause values to become negative | |
202 | // as some properties cannot be set to negative values. | |
203 | if(n == 0 || n == 1){ return n; } | |
204 | var p = .3; | |
205 | var s = p / 4; | |
206 | n = n - 1; | |
207 | return -1 * Math.pow(2, 10 * n) * Math.sin((n - s) * (2 * Math.PI) / p); | |
208 | }, | |
209 | ||
210 | elasticOut: function(/* Decimal? */n){ | |
211 | // summary: | |
212 | // An easing function that elasticly snaps around the target value, | |
213 | // near the end of the Animation | |
214 | // | |
215 | // description: | |
216 | // An easing function that elasticly snaps around the target value, | |
217 | // near the end of the Animation | |
218 | // | |
219 | // Use caution when the elasticity will cause values to become | |
220 | // negative as some properties cannot be set to negative values. | |
221 | if(n==0 || n == 1){ return n; } | |
222 | var p = .3; | |
223 | var s = p / 4; | |
224 | return Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p) + 1; | |
225 | }, | |
226 | ||
227 | elasticInOut: function(/* Decimal? */n){ | |
228 | // summary: | |
229 | // An easing function that elasticly snaps around the value, near | |
230 | // the beginning and end of the Animation. | |
231 | // | |
232 | // description: | |
233 | // An easing function that elasticly snaps around the value, near | |
234 | // the beginning and end of the Animation. | |
235 | // | |
236 | // Use caution when the elasticity will cause values to become | |
237 | // negative as some properties cannot be set to negative values. | |
238 | if(n == 0) return 0; | |
239 | n = n * 2; | |
240 | if(n == 2) return 1; | |
241 | var p = .3 * 1.5; | |
242 | var s = p / 4; | |
243 | if(n < 1){ | |
244 | n -= 1; | |
245 | return -.5 * (Math.pow(2, 10 * n) * Math.sin((n - s) * (2 * Math.PI) / p)); | |
246 | } | |
247 | n -= 1; | |
248 | return .5 * (Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p)) + 1; | |
249 | }, | |
250 | ||
251 | bounceIn: function(/* Decimal? */n){ | |
252 | // summary: | |
253 | // An easing function that 'bounces' near the beginning of an Animation | |
254 | return (1 - dojo.fx.easing.bounceOut(1 - n)); // Decimal | |
255 | }, | |
256 | ||
257 | bounceOut: function(/* Decimal? */n){ | |
258 | // summary: | |
259 | // An easing function that 'bounces' near the end of an Animation | |
260 | var s = 7.5625; | |
261 | var p = 2.75; | |
262 | var l; | |
263 | if(n < (1 / p)){ | |
264 | l = s * Math.pow(n, 2); | |
265 | }else if(n < (2 / p)){ | |
266 | n -= (1.5 / p); | |
267 | l = s * Math.pow(n, 2) + .75; | |
268 | }else if(n < (2.5 / p)){ | |
269 | n -= (2.25 / p); | |
270 | l = s * Math.pow(n, 2) + .9375; | |
271 | }else{ | |
272 | n -= (2.625 / p); | |
273 | l = s * Math.pow(n, 2) + .984375; | |
274 | } | |
275 | return l; | |
276 | }, | |
277 | ||
278 | bounceInOut: function(/* Decimal? */n){ | |
279 | // summary: | |
280 | // An easing function that 'bounces' at the beginning and end of the Animation | |
281 | if(n < 0.5){ return dojo.fx.easing.bounceIn(n * 2) / 2; } | |
282 | return (dojo.fx.easing.bounceOut(n * 2 - 1) / 2) + 0.5; // Decimal | |
283 | } | |
284 | }; | |
285 | ||
2f01fe57 | 286 | } |