1 define("dojo/fx/easing", ["../_base/lang"], function(lang){
8 // Collection of easing functions to use beyond the default
9 // `dojo._defaultEasing` function.
11 // Easing functions are used to manipulate the iteration through
12 // an `dojo.Animation`s _Line. _Line being the properties of an Animation,
13 // and the easing function progresses through that Line determining
14 // how quickly (or slowly) it should go. Or more accurately: modify
15 // the value of the _Line based on the percentage of animation completed.
17 // All functions follow a simple naming convention of "ease type" + "when".
18 // If the name of the function ends in Out, the easing described appears
19 // towards the end of the animation. "In" means during the beginning,
20 // and InOut means both ranges of the Animation will applied, both
23 // One does not call the easing function directly, it must be passed to
24 // the `easing` property of an animation.
26 // | dojo.require("dojo.fx.easing");
27 // | var anim = dojo.fadeOut({
30 // | // note there is no ()
31 // | easing: dojo.fx.easing.quadIn
35 linear: function(/* Decimal? */n){
37 // A linear easing function
41 quadIn: function(/* Decimal? */n){
42 return Math.pow(n, 2);
45 quadOut: function(/* Decimal? */n){
46 return n * (n - 2) * -1;
49 quadInOut: function(/* Decimal? */n){
51 if(n < 1){ return Math.pow(n, 2) / 2; }
52 return -1 * ((--n) * (n - 2) - 1) / 2;
55 cubicIn: function(/* Decimal? */n){
56 return Math.pow(n, 3);
59 cubicOut: function(/* Decimal? */n){
60 return Math.pow(n - 1, 3) + 1;
63 cubicInOut: function(/* Decimal? */n){
65 if(n < 1){ return Math.pow(n, 3) / 2; }
67 return (Math.pow(n, 3) + 2) / 2;
70 quartIn: function(/* Decimal? */n){
71 return Math.pow(n, 4);
74 quartOut: function(/* Decimal? */n){
75 return -1 * (Math.pow(n - 1, 4) - 1);
78 quartInOut: function(/* Decimal? */n){
80 if(n < 1){ return Math.pow(n, 4) / 2; }
82 return -1 / 2 * (Math.pow(n, 4) - 2);
85 quintIn: function(/* Decimal? */n){
86 return Math.pow(n, 5);
89 quintOut: function(/* Decimal? */n){
90 return Math.pow(n - 1, 5) + 1;
93 quintInOut: function(/* Decimal? */n){
95 if(n < 1){ return Math.pow(n, 5) / 2; }
97 return (Math.pow(n, 5) + 2) / 2;
100 sineIn: function(/* Decimal? */n){
101 return -1 * Math.cos(n * (Math.PI / 2)) + 1;
104 sineOut: function(/* Decimal? */n){
105 return Math.sin(n * (Math.PI / 2));
108 sineInOut: function(/* Decimal? */n){
109 return -1 * (Math.cos(Math.PI * n) - 1) / 2;
112 expoIn: function(/* Decimal? */n){
113 return (n == 0) ? 0 : Math.pow(2, 10 * (n - 1));
116 expoOut: function(/* Decimal? */n){
117 return (n == 1) ? 1 : (-1 * Math.pow(2, -10 * n) + 1);
120 expoInOut: function(/* Decimal? */n){
121 if(n == 0){ return 0; }
122 if(n == 1){ return 1; }
124 if(n < 1){ return Math.pow(2, 10 * (n - 1)) / 2; }
126 return (-1 * Math.pow(2, -10 * n) + 2) / 2;
129 circIn: function(/* Decimal? */n){
130 return -1 * (Math.sqrt(1 - Math.pow(n, 2)) - 1);
133 circOut: function(/* Decimal? */n){
135 return Math.sqrt(1 - Math.pow(n, 2));
138 circInOut: function(/* Decimal? */n){
140 if(n < 1){ return -1 / 2 * (Math.sqrt(1 - Math.pow(n, 2)) - 1); }
142 return 1 / 2 * (Math.sqrt(1 - Math.pow(n, 2)) + 1);
145 backIn: function(/* Decimal? */n){
147 // An easing function that starts away from the target,
148 // and quickly accelerates towards the end value.
150 // Use caution when the easing will cause values to become
151 // negative as some properties cannot be set to negative values.
153 return Math.pow(n, 2) * ((s + 1) * n - s);
156 backOut: function(/* Decimal? */n){
158 // An easing function that pops past the range briefly, and slowly comes back.
160 // An easing function that pops past the range briefly, and slowly comes back.
162 // Use caution when the easing will cause values to become negative as some
163 // properties cannot be set to negative values.
167 return Math.pow(n, 2) * ((s + 1) * n + s) + 1;
170 backInOut: function(/* Decimal? */n){
172 // An easing function combining the effects of `backIn` and `backOut`
174 // An easing function combining the effects of `backIn` and `backOut`.
175 // Use caution when the easing will cause values to become negative
176 // as some properties cannot be set to negative values.
177 var s = 1.70158 * 1.525;
179 if(n < 1){ return (Math.pow(n, 2) * ((s + 1) * n - s)) / 2; }
181 return (Math.pow(n, 2) * ((s + 1) * n + s) + 2) / 2;
184 elasticIn: function(/* Decimal? */n){
186 // An easing function the elastically snaps from the start value
188 // An easing function the elastically snaps from the start value
190 // Use caution when the elasticity will cause values to become negative
191 // as some properties cannot be set to negative values.
192 if(n == 0 || n == 1){ return n; }
196 return -1 * Math.pow(2, 10 * n) * Math.sin((n - s) * (2 * Math.PI) / p);
199 elasticOut: function(/* Decimal? */n){
201 // An easing function that elasticly snaps around the target value,
202 // near the end of the Animation
204 // An easing function that elasticly snaps around the target value,
205 // near the end of the Animation
207 // Use caution when the elasticity will cause values to become
208 // negative as some properties cannot be set to negative values.
209 if(n==0 || n == 1){ return n; }
212 return Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p) + 1;
215 elasticInOut: function(/* Decimal? */n){
217 // An easing function that elasticly snaps around the value, near
218 // the beginning and end of the Animation.
220 // An easing function that elasticly snaps around the value, near
221 // the beginning and end of the Animation.
223 // Use caution when the elasticity will cause values to become
224 // negative as some properties cannot be set to negative values.
232 return -.5 * (Math.pow(2, 10 * n) * Math.sin((n - s) * (2 * Math.PI) / p));
235 return .5 * (Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p)) + 1;
238 bounceIn: function(/* Decimal? */n){
240 // An easing function that 'bounces' near the beginning of an Animation
241 return (1 - easingFuncs.bounceOut(1 - n)); // Decimal
244 bounceOut: function(/* Decimal? */n){
246 // An easing function that 'bounces' near the end of an Animation
251 l = s * Math.pow(n, 2);
252 }else if(n < (2 / p)){
254 l = s * Math.pow(n, 2) + .75;
255 }else if(n < (2.5 / p)){
257 l = s * Math.pow(n, 2) + .9375;
260 l = s * Math.pow(n, 2) + .984375;
265 bounceInOut: function(/* Decimal? */n){
267 // An easing function that 'bounces' at the beginning and end of the Animation
268 if(n < 0.5){ return easingFuncs.bounceIn(n * 2) / 2; }
269 return (easingFuncs.bounceOut(n * 2 - 1) / 2) + 0.5; // Decimal
273 lang.setObject("dojo.fx.easing", easingFuncs);