-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEffects.js
More file actions
191 lines (156 loc) · 6.69 KB
/
Effects.js
File metadata and controls
191 lines (156 loc) · 6.69 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
if(!javaxt) var javaxt={};
if(!javaxt.dhtml) javaxt.dhtml={};
//******************************************************************************
//** Effects
//*****************************************************************************/
/**
* Used to dynamically apply transition effects to elements.
*
******************************************************************************/
javaxt.dhtml.Effects = function() {
var me = this;
//**************************************************************************
//** fadeIn
//**************************************************************************
/** Used to gradually update the opacity of a given element. Assumes the
* element style is initially set to display:none;
*/
this.fadeIn = function(el, transitionEffect, duration, callback){
el.style.opacity = 0;
el.style.display = "";
me.setTransition(el, transitionEffect, duration);
setTimeout(function(){
el.style.opacity = "";
setTimeout(function(){
removeTransition(el);
if (callback) callback.apply(el, []);
}, duration+50);
}, 50);
};
//**************************************************************************
//** fadeOut
//**************************************************************************
/** Used to gradually update the opacity of a given element until it is no
* longer visible.
*/
this.fadeOut = function(el, transitionEffect, duration, callback){
me.setTransition(el, transitionEffect, duration);
setTimeout(function(){
el.style.opacity = 0;
setTimeout(function(){
el.style.display = "none";
removeTransition(el);
if (callback) callback.apply(el, []);
}, duration+50);
}, 50);
};
//**************************************************************************
//** setTransition
//**************************************************************************
/** Used to set the transition style for a given element.
*/
this.setTransition = function(el, transitionEffect, duration){
if (isNaN(duration) || duration<=0) return;
var points = getPoints(transitionEffect);
setTransition(el, duration, points);
};
//**************************************************************************
//** getPoints
//**************************************************************************
var getPoints = function(transitionEffect){
if (isArray(transitionEffect)){
return transitionEffect;
}
else{
var points = javaxt.dhtml.Transitions[transitionEffect];
if (!points) points = javaxt.dhtml.Transitions["ease"];
return points;
}
};
//**************************************************************************
//** isArray
//**************************************************************************
var isArray = function(obj){
return (Object.prototype.toString.call(obj)==='[object Array]');
};
//**************************************************************************
//** setTransition
//**************************************************************************
/** Used to set or update the transition style for a the given element.
* all 500ms cubic-bezier(0.52, 0.075, 0.47, 0.895)
*/
var setTransition = function(el, t, arr) {
var x1 = arr[0];
var y1 = arr[1];
var x2 = arr[2];
var y2 = arr[3];
// set all transition types. ugly ugly vendor prefixes
el.style.WebkitTransition =
el.style.MozTransition =
el.style.MsTransition =
el.style.OTransition =
el.style.transition =
'all ' + t + 'ms cubic-bezier' +
'(' + x1 + ', ' + y1 + ', ' + x2 + ', ' + y2 + ')';
if ( !supportsBezierRange ) {
var wy1, wy2;
if (y1 > 1) wy1 = 1;
if (y1 < 0) wy1 = 0;
if (y2 > 1) wy2 = 1;
if (y2 < 0) wy2 = 0;
el.style.WebkitTransition = 'all ' + t + 'ms cubic-bezier' + '(' + x1 + ', ' + wy1 + ', ' + x2 + ', ' + wy2 + ')';
}
};
//**************************************************************************
//** removeTransition
//**************************************************************************
var removeTransition = function(el){
el.style.WebkitTransition =
el.style.MozTransition =
el.style.MsTransition =
el.style.OTransition =
el.style.transition = "";
if ( !supportsBezierRange ) {
el.style.WebkitTransition = "";
}
};
//**************************************************************************
//** supportsBezierRange
//**************************************************************************
var supportsBezierRange = (function() {
var el = document.createElement('div');
el.style.WebkitTransitionTimingFunction = 'cubic-bezier(1,0,0,1.1)';
return !!el.style.WebkitTransitionTimingFunction.length;
})();
};
javaxt.dhtml.Transitions = {
linear : [0.250, 0.250, 0.750, 0.750],
ease : [0.250, 0.100, 0.250, 1.000],
easeIn : [0.420, 0.000, 1.000, 1.000],
easeOut : [0.000, 0.000, 0.580, 1.000],
easeInOut : [0.420, 0.000, 0.580, 1.000],
easeInQuad : [0.550, 0.085, 0.680, 0.530],
easeInCubic : [0.550, 0.055, 0.675, 0.190],
easeInQuart : [0.895, 0.030, 0.685, 0.220],
easeInQuint : [0.755, 0.050, 0.855, 0.060],
easeInSine : [0.470, 0.000, 0.745, 0.715],
easeInExpo : [0.950, 0.050, 0.795, 0.035],
easeInCirc : [0.600, 0.040, 0.980, 0.335],
easeInBack : [0.600, -0.280, 0.735, 0.045],
easeOutQuad : [0.250, 0.460, 0.450, 0.940],
easeOutCubic : [0.215, 0.610, 0.355, 1.000],
easeOutQuart : [0.165, 0.840, 0.440, 1.000],
easeOutQuint : [0.230, 1.000, 0.320, 1.000],
easeOutSine : [0.390, 0.575, 0.565, 1.000],
easeOutExpo : [0.190, 1.000, 0.220, 1.000],
easeOutCirc : [0.075, 0.820, 0.165, 1.000],
easeOutBack : [0.175, 0.885, 0.320, 1.275],
easeInOutQuad : [0.455, 0.030, 0.515, 0.955],
easeInOutCubic : [0.645, 0.045, 0.355, 1.000],
easeInOutQuart : [0.770, 0.000, 0.175, 1.000],
easeInOutQuint : [0.860, 0.000, 0.070, 1.000],
easeInOutSine : [0.445, 0.050, 0.550, 0.950],
easeInOutExpo : [1.000, 0.000, 0.000, 1.000],
easeInOutCirc : [0.785, 0.135, 0.150, 0.860],
easeInOutBack : [0.680, -0.550, 0.265, 1.550]
};