-
Notifications
You must be signed in to change notification settings - Fork 3
/
leta.easings.js
129 lines (104 loc) · 3.39 KB
/
leta.easings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* The equations defined here are open source under BSD License.
* http://www.robertpenner.com/easing_terms_of_use.html (c) 2003 Robert Penner
* Adapted to single time-based by
*/
(function (win, undefined) {
var easings = {
easeOut: function (t) {
return Math.sin(t * Math.PI / 2);
}
, easeOutStrong: function (t) {
return (t == 1) ? 1 : 1 - Math.pow(2, -10 * t);
}
, easeIn: function (t) {
return t * t;
}
, easeInStrong: function (t) {
return (t == 0) ? 0 : Math.pow(2, 10 * (t - 1));
}
, easeOutBounce: function(pos) {
if ((pos) < (1/2.75)) {
return (7.5625*pos*pos);
} else if (pos < (2/2.75)) {
return (7.5625*(pos-=(1.5/2.75))*pos + .75);
} else if (pos < (2.5/2.75)) {
return (7.5625*(pos-=(2.25/2.75))*pos + .9375);
} else {
return (7.5625*(pos-=(2.625/2.75))*pos + .984375);
}
}
, easeInBack: function(pos){
var s = 1.70158;
return (pos)*pos*((s+1)*pos - s);
}
, easeOutBack: function(pos){
var s = 1.70158;
return (pos=pos-1)*pos*((s+1)*pos + s) + 1;
}
, bounce: function (t) {
if (t < (1 / 2.75)) {
return 7.5625 * t * t;
}
if (t < (2 / 2.75)) {
return 7.5625 * (t -= (1.5 / 2.75)) * t + 0.75;
}
if (t < (2.5 / 2.75)) {
return 7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375;
}
return 7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375;
}
, bouncePast: function (pos) {
if (pos < (1 / 2.75)) {
return (7.5625 * pos * pos);
} else if (pos < (2 / 2.75)) {
return 2 - (7.5625 * (pos -= (1.5 / 2.75)) * pos + .75);
} else if (pos < (2.5 / 2.75)) {
return 2 - (7.5625 * (pos -= (2.25 / 2.75)) * pos + .9375);
} else {
return 2 - (7.5625 * (pos -= (2.625 / 2.75)) * pos + .984375);
}
}
, swingTo: function(pos) {
var s = 1.70158;
return (pos -= 1) * pos * ((s + 1) * pos + s) + 1;
}
, swingFrom: function (pos) {
var s = 1.70158;
return pos * pos * ((s + 1) * pos - s);
}
, elastic: function(pos) {
return -1 * Math.pow(4, -8 * pos) * Math.sin((pos * 6 - 1) * (2 * Math.PI) / 2) + 1;
}
, spring: function(pos) {
return 1 - (Math.cos(pos * 4.5 * Math.PI) * Math.exp(-pos * 6));
}
, blink: function(pos, blinks) {
return Math.round(pos*(blinks||5)) % 2;
}
, pulse: function(pos, pulses) {
return (-Math.cos((pos*((pulses||5)-.5)*2)*Math.PI)/2) + .5;
}
, wobble: function(pos) {
return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5;
}
, sinusoidal: function(pos) {
return (-Math.cos(pos*Math.PI)/2) + 0.5;
}
, flicker: function(pos) {
var pos = pos + (Math.random()-0.5)/5;
return easings.sinusoidal(pos < 0 ? 0 : pos > 1 ? 1 : pos);
}
, mirror: function(pos) {
if (pos < 0.5)
return easings.sinusoidal(pos*2);
else
return easings.sinusoidal(1-(pos-0.5)*2);
}
};
if (typeof Leta != 'undefined') {
if (!!Leta.extend) { Leta.extend({easings: easings}) } else { Leta.easings = easings }
} else {
win.Leta = {};
Leta.easings = easings;
}
})(window);