-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfader.js
More file actions
64 lines (59 loc) · 1.93 KB
/
fader.js
File metadata and controls
64 lines (59 loc) · 1.93 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
//opacity detection code. IE uses a different method
var useOpacity =
(typeof document.createElement("div").style.opacity !== 'undefined');
var useFilter =
!useOpacity && (typeof document.createElement("div").style.filter !== 'undefined');
function update_opacities(){
for(var i=0;i<this.elements.length;i++){
if(useOpacity){
this.elements[i].style.opacity = this.fade_opacity/100;
}else if (useFilter){
this.elements[i].style.filter = "alpha(opacity=" + this.fade_opacity + ")";
}
}
}
function fader(elements, startopacity){
this.fade_opacity = (typeof startopacity !== 'undefined') ? startopacity : 100;
this.elements = elements;
this.popto = popto;
this.fadeto = fadeto;
this.updating;
this.update_opacities = update_opacities;
this.update_opacities();
}
function popto(val){
clearTimeout(this.updating);
this.fade_opacity = val;
this.update_opacities();
}
function update(element, stop, step, delay, done){
if (element.fade_opacity !== stop){
element.updating = setTimeout(function(){update(element, stop, step, delay, done)}, delay);
if (Math.abs(element.fade_opacity - stop) < step){
element.fade_opacity = stop;
}else{
element.fade_opacity += element.fade_opacity > stop ? -step : step;
}
element.update_opacities();
}else{
if (typeof done !== 'undefined'){
done();
}
}
}
function fadeto(stop, step, delay, done){
step = (typeof step !== 'undefined') ? step : 1;
delay = (typeof delay !== 'undefined') ? delay : 33;
clearTimeout(this.updating);
update(this, stop, step, delay, done);
}
function get_fadeelements(){
var elements = document.getElementsByTagName("*");
var fadeelements = [];
for (var i=0;i<elements.length;i++){
if(elements[i].className.indexOf("fade") !== -1){
fadeelements.push(elements[i]);
}
}
return fadeelements;
}