1 define("dojo/fx/easing", ["../_base/lang"], function(lang) {
5 // This module defines standard easing functions that are useful for animations.
7 var easingFuncs = /*===== dojo.fx.easing= =====*/ {
9 // Collection of easing functions to use beyond the default
10 // `dojo._defaultEasing` function.
14 // Easing functions are used to manipulate the iteration through
15 // an `dojo.Animation`s _Line. _Line being the properties of an Animation,
16 // and the easing function progresses through that Line determing
17 // how quickly (or slowly) it should go. Or more accurately: modify
18 // the value of the _Line based on the percentage of animation completed.
20 // All functions follow a simple naming convention of "ease type" + "when".
21 // If the name of the function ends in Out, the easing described appears
22 // towards the end of the animation. "In" means during the beginning,
23 // and InOut means both ranges of the Animation will applied, both
26 // One does not call the easing function directly, it must be passed to
27 // the `easing` property of an animation.
30 // | dojo.require("dojo.fx.easing");
31 // | var anim = dojo.fadeOut({
34 // | // note there is no ()
35 // | easing: dojo.fx.easing.quadIn
39 linear: function(/* Decimal? */n){
40 // summary: A linear easing function
44 quadIn: function(/* Decimal? */n){
45 return Math.pow(n, 2);
48 quadOut: function(/* Decimal? */n){
49 return n * (n - 2) * -1;
52 quadInOut: function(/* Decimal? */n){
54 if(n < 1){ return Math.pow(n, 2) / 2; }
55 return -1 * ((--n) * (n - 2) - 1) / 2;
58 cubicIn: function(/* Decimal? */n){
59 return Math.pow(n, 3);
62 cubicOut: function(/* Decimal? */n){
63 return Math.pow(n - 1, 3) + 1;
66 cubicInOut: function(/* Decimal? */n){
68 if(n < 1){ return Math.pow(n, 3) / 2; }
70 return (Math.pow(n, 3) + 2) / 2;
73 quartIn: function(/* Decimal? */n){
74 return Math.pow(n, 4);
77 quartOut: function(/* Decimal? */n){
78 return -1 * (Math.pow(n - 1, 4) - 1);
81 quartInOut: function(/* Decimal? */n){
83 if(n < 1){ return Math.pow(n, 4) / 2; }
85 return -1 / 2 * (Math.pow(n, 4) - 2);
88 quintIn: function(/* Decimal? */n){
89 return Math.pow(n, 5);
92 quintOut: function(/* Decimal? */n){
93 return Math.pow(n - 1, 5) + 1;
96 quintInOut: function(/* Decimal? */n){
98 if(n < 1){ return Math.pow(n, 5) / 2; }
100 return (Math.pow(n, 5) + 2) / 2;
103 sineIn: function(/* Decimal? */n){
104 return -1 * Math.cos(n * (Math.PI / 2)) + 1;
107 sineOut: function(/* Decimal? */n){
108 return Math.sin(n * (Math.PI / 2));
111 sineInOut: function(/* Decimal? */n){
112 return -1 * (Math.cos(Math.PI * n) - 1) / 2;
115 expoIn: function(/* Decimal? */n){
116 return (n == 0) ? 0 : Math.pow(2, 10 * (n - 1));
119 expoOut: function(/* Decimal? */n){
120 return (n == 1) ? 1 : (-1 * Math.pow(2, -10 * n) + 1);
123 expoInOut: function(/* Decimal? */n){
124 if(n == 0){ return 0; }
125 if(n == 1){ return 1; }
127 if(n < 1){ return Math.pow(2, 10 * (n - 1)) / 2; }
129 return (-1 * Math.pow(2, -10 * n) + 2) / 2;
132 circIn: function(/* Decimal? */n){
133 return -1 * (Math.sqrt(1 - Math.pow(n, 2)) - 1);
136 circOut: function(/* Decimal? */n){
138 return Math.sqrt(1 - Math.pow(n, 2));
141 circInOut: function(/* Decimal? */n){
143 if(n < 1){ return -1 / 2 * (Math.sqrt(1 - Math.pow(n, 2)) - 1); }
145 return 1 / 2 * (Math.sqrt(1 - Math.pow(n, 2)) + 1);
148 backIn: function(/* Decimal? */n){
150 // An easing function that starts away from the target,
151 // and quickly accelerates towards the end value.
153 // Use caution when the easing will cause values to become
154 // negative as some properties cannot be set to negative values.
156 return Math.pow(n, 2) * ((s + 1) * n - s);
159 backOut: function(/* Decimal? */n){
161 // An easing function that pops past the range briefly, and slowly comes back.
164 // An easing function that pops past the range briefly, and slowly comes back.
166 // Use caution when the easing will cause values to become negative as some
167 // properties cannot be set to negative values.
171 return Math.pow(n, 2) * ((s + 1) * n + s) + 1;
174 backInOut: function(/* Decimal? */n){
176 // An easing function combining the effects of `backIn` and `backOut`
179 // An easing function combining the effects of `backIn` and `backOut`.
180 // Use caution when the easing will cause values to become negative
181 // as some properties cannot be set to negative values.
182 var s = 1.70158 * 1.525;
184 if(n < 1){ return (Math.pow(n, 2) * ((s + 1) * n - s)) / 2; }
186 return (Math.pow(n, 2) * ((s + 1) * n + s) + 2) / 2;
189 elasticIn: function(/* Decimal? */n){
191 // An easing function the elastically snaps from the start value
194 // An easing function the elastically snaps from the start value
196 // Use caution when the elasticity will cause values to become negative
197 // as some properties cannot be set to negative values.
198 if(n == 0 || n == 1){ return n; }
202 return -1 * Math.pow(2, 10 * n) * Math.sin((n - s) * (2 * Math.PI) / p);
205 elasticOut: function(/* Decimal? */n){
207 // An easing function that elasticly snaps around the target value,
208 // near the end of the Animation
211 // An easing function that elasticly snaps around the target value,
212 // near the end of the Animation
214 // Use caution when the elasticity will cause values to become
215 // negative as some properties cannot be set to negative values.
216 if(n==0 || n == 1){ return n; }
219 return Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p) + 1;
222 elasticInOut: function(/* Decimal? */n){
224 // An easing function that elasticly snaps around the value, near
225 // the beginning and end of the Animation.
228 // An easing function that elasticly snaps around the value, near
229 // the beginning and end of the Animation.
231 // Use caution when the elasticity will cause values to become
232 // negative as some properties cannot be set to negative values.
240 return -.5 * (Math.pow(2, 10 * n) * Math.sin((n - s) * (2 * Math.PI) / p));
243 return .5 * (Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p)) + 1;
246 bounceIn: function(/* Decimal? */n){
248 // An easing function that 'bounces' near the beginning of an Animation
249 return (1 - easingFuncs.bounceOut(1 - n)); // Decimal
252 bounceOut: function(/* Decimal? */n){
254 // An easing function that 'bounces' near the end of an Animation
259 l = s * Math.pow(n, 2);
260 }else if(n < (2 / p)){
262 l = s * Math.pow(n, 2) + .75;
263 }else if(n < (2.5 / p)){
265 l = s * Math.pow(n, 2) + .9375;
268 l = s * Math.pow(n, 2) + .984375;
273 bounceInOut: function(/* Decimal? */n){
275 // An easing function that 'bounces' at the beginning and end of the Animation
276 if(n < 0.5){ return easingFuncs.bounceIn(n * 2) / 2; }
277 return (easingFuncs.bounceOut(n * 2 - 1) / 2) + 0.5; // Decimal
281 lang.setObject("dojo.fx.easing", easingFuncs);