initial import
[roojs1] / Roo / lib / Easing.js
1 /*
2  * Portions of this file are based on pieces of Yahoo User Interface Library
3  * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
4  * YUI licensed under the BSD License:
5  * http://developer.yahoo.net/yui/license.txt
6  * <script type="text/javascript">
7  *
8  */
9 Roo.lib.Easing = {
10
11
12     easeNone: function (t, b, c, d) {
13         return c * t / d + b;
14     },
15
16
17     easeIn: function (t, b, c, d) {
18         return c * (t /= d) * t + b;
19     },
20
21
22     easeOut: function (t, b, c, d) {
23         return -c * (t /= d) * (t - 2) + b;
24     },
25
26
27     easeBoth: function (t, b, c, d) {
28         if ((t /= d / 2) < 1) {
29             return c / 2 * t * t + b;
30         }
31
32         return -c / 2 * ((--t) * (t - 2) - 1) + b;
33     },
34
35
36     easeInStrong: function (t, b, c, d) {
37         return c * (t /= d) * t * t * t + b;
38     },
39
40
41     easeOutStrong: function (t, b, c, d) {
42         return -c * ((t = t / d - 1) * t * t * t - 1) + b;
43     },
44
45
46     easeBothStrong: function (t, b, c, d) {
47         if ((t /= d / 2) < 1) {
48             return c / 2 * t * t * t * t + b;
49         }
50
51         return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
52     },
53
54
55
56     elasticIn: function (t, b, c, d, a, p) {
57         if (t == 0) {
58             return b;
59         }
60         if ((t /= d) == 1) {
61             return b + c;
62         }
63         if (!p) {
64             p = d * .3;
65         }
66
67         if (!a || a < Math.abs(c)) {
68             a = c;
69             var s = p / 4;
70         }
71         else {
72             var s = p / (2 * Math.PI) * Math.asin(c / a);
73         }
74
75         return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
76     },
77
78
79     elasticOut: function (t, b, c, d, a, p) {
80         if (t == 0) {
81             return b;
82         }
83         if ((t /= d) == 1) {
84             return b + c;
85         }
86         if (!p) {
87             p = d * .3;
88         }
89
90         if (!a || a < Math.abs(c)) {
91             a = c;
92             var s = p / 4;
93         }
94         else {
95             var s = p / (2 * Math.PI) * Math.asin(c / a);
96         }
97
98         return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
99     },
100
101
102     elasticBoth: function (t, b, c, d, a, p) {
103         if (t == 0) {
104             return b;
105         }
106
107         if ((t /= d / 2) == 2) {
108             return b + c;
109         }
110
111         if (!p) {
112             p = d * (.3 * 1.5);
113         }
114
115         if (!a || a < Math.abs(c)) {
116             a = c;
117             var s = p / 4;
118         }
119         else {
120             var s = p / (2 * Math.PI) * Math.asin(c / a);
121         }
122
123         if (t < 1) {
124             return -.5 * (a * Math.pow(2, 10 * (t -= 1)) *
125                           Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
126         }
127         return a * Math.pow(2, -10 * (t -= 1)) *
128                Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
129     },
130
131
132
133     backIn: function (t, b, c, d, s) {
134         if (typeof s == 'undefined') {
135             s = 1.70158;
136         }
137         return c * (t /= d) * t * ((s + 1) * t - s) + b;
138     },
139
140
141     backOut: function (t, b, c, d, s) {
142         if (typeof s == 'undefined') {
143             s = 1.70158;
144         }
145         return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
146     },
147
148
149     backBoth: function (t, b, c, d, s) {
150         if (typeof s == 'undefined') {
151             s = 1.70158;
152         }
153
154         if ((t /= d / 2 ) < 1) {
155             return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
156         }
157         return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
158     },
159
160
161     bounceIn: function (t, b, c, d) {
162         return c - Roo.lib.Easing.bounceOut(d - t, 0, c, d) + b;
163     },
164
165
166     bounceOut: function (t, b, c, d) {
167         if ((t /= d) < (1 / 2.75)) {
168             return c * (7.5625 * t * t) + b;
169         } else if (t < (2 / 2.75)) {
170             return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
171         } else if (t < (2.5 / 2.75)) {
172             return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
173         }
174         return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
175     },
176
177
178     bounceBoth: function (t, b, c, d) {
179         if (t < d / 2) {
180             return Roo.lib.Easing.bounceIn(t * 2, 0, c, d) * .5 + b;
181         }
182         return Roo.lib.Easing.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
183     }
184 };