Skip to content

Commit ebf4fb1

Browse files
added: in-elastic, out-elastic, in-out-elastic
1 parent 5aebbdd commit ebf4fb1

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Readme.md

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
- inBounce
3232
- outBounce
3333
- inOutBounce
34+
- inElastic
35+
- outElastic
36+
- inOutElastic
3437

3538
## Aliases
3639

@@ -61,6 +64,9 @@
6164
- in-bounce
6265
- out-bounce
6366
- in-out-bounce
67+
- in-elastic
68+
- out-elastic
69+
- in-out-elastic
6470

6571
## Example
6672

index.js

+31
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,34 @@ exports.inOutBounce = function(n){
139139
return exports.outBounce(n * 2 - 1) * .5 + .5;
140140
};
141141

142+
exports.inElastic = function(n){
143+
var s, a = 0.1, p = 0.4;
144+
if ( n === 0 ) return 0;
145+
if ( n === 1 ) return 1;
146+
if ( !a || a < 1 ) { a = 1; s = p / 4; }
147+
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
148+
return - ( a * Math.pow( 2, 10 * ( n -= 1 ) ) * Math.sin( ( n - s ) * ( 2 * Math.PI ) / p ) );
149+
};
150+
151+
exports.outElastic = function(n){
152+
var s, a = 0.1, p = 0.4;
153+
if ( n === 0 ) return 0;
154+
if ( n === 1 ) return 1;
155+
if ( !a || a < 1 ) { a = 1; s = p / 4; }
156+
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
157+
return ( a * Math.pow( 2, - 10 * n) * Math.sin( ( n - s ) * ( 2 * Math.PI ) / p ) + 1 );
158+
};
159+
160+
exports.inOutElastic = function(n){
161+
var s, a = 0.1, p = 0.4;
162+
if ( n === 0 ) return 0;
163+
if ( n === 1 ) return 1;
164+
if ( !a || a < 1 ) { a = 1; s = p / 4; }
165+
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
166+
if ( ( n *= 2 ) < 1 ) return - 0.5 * ( a * Math.pow( 2, 10 * ( n -= 1 ) ) * Math.sin( ( n - s ) * ( 2 * Math.PI ) / p ) );
167+
return a * Math.pow( 2, -10 * ( n -= 1 ) ) * Math.sin( ( n - s ) * ( 2 * Math.PI ) / p ) * 0.5 + 1;
168+
};
169+
142170
// aliases
143171

144172
exports['in-quad'] = exports.inQuad;
@@ -168,3 +196,6 @@ exports['in-out-back'] = exports.inOutBack;
168196
exports['in-bounce'] = exports.inBounce;
169197
exports['out-bounce'] = exports.outBounce;
170198
exports['in-out-bounce'] = exports.inOutBounce;
199+
exports['in-elastic'] = exports.inElastic;
200+
exports['out-elastic'] = exports.outElastic;
201+
exports['in-out-elastic'] = exports.inOutElastic;

0 commit comments

Comments
 (0)