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
|
// usage: eff_fade_in(id, [speed, fps, callback])
// usage: eff_fade_out(id, [speed, fps, callback])
// Warning: callback must be a user created function! otherwise Firefox will go haywire
// global store for any fade variables
var _eff_fade_store = new Array();
window._eff_debug = function(a) { }
function eff_fade_in(id, speed, fps, callback) { _eff_fade(id, speed, fps, -1, callback); }
function eff_fade_out(id, speed, fps, callback) { _eff_fade(id, speed, fps, 1, callback); }
function _eff_fade(id, speed, fps, direction, callback)
{
if(typeof(speed) == 'undefined') speed = 0;
if(typeof(fps) == 'undefined') fps = 0;
if(typeof(callback) != 'function') callback = false;
speed = parseInt(speed);
fps = parseInt(fps);
if(speed < 100 || speed > 10000) speed = 500;
if(fps < 1 || fps > 100) fps = 25;
var el = document.getElementById(id);
if(!el) {
alert('No such element: '+id);
return false;
}
if(typeof(_eff_fade_store[id]) == 'undefined')
_eff_fade_store[id] = new Array();
if(typeof(_eff_fade_store[id]['frame']) != 'undefined') {
// make it change direction?
return;
} else {
//
// NOTE: we do not care which is the initial visibility of the element
//
// no need to fade again to same direction
if(direction < 0 && el.style.visibility == 'visible')
return;
if(direction > 0 && (el.style.visibility == 'hidden'))
return;
}
// hide the element after fade out is complete
if(direction > 0)
_eff_fade_store[id]['action'] = function(a) { a.style.visibility = 'hidden'; }
else
_eff_fade_store[id]['action'] = undefined;
_eff_fade_store[id]['element'] = el;
_eff_fade_store[id]['frame'] = 100 * direction;
_eff_fade_store[id]['step'] = 100 / (speed / (1000 / fps));
_eff_fade_store[id]['interval'] = setInterval("_eff_fade_run('"+id+"')", eval(1000/fps));
_eff_fade_store[id]['callback'] = callback;
_eff_fade_run(id);
el.style.visibility = 'visible';
el.style.zoom = '1'; // IE hack
return true;
}
function _eff_fade_run(id)
{
var el = _eff_fade_store[id]['element'];
var interval = _eff_fade_store[id]['interval'];
var frame = _eff_fade_store[id]['frame'];
var step = _eff_fade_store[id]['step'];
var opacity = 0;
if(frame < 0) {
frame += step;
if(frame > 0)
frame = 0;
opacity = (frame + 100).toFixed(2);
} else if(frame > 0) {
frame -= step;
if(frame < 0)
frame = 0;
opacity = frame.toFixed(2);
}
el.style.opacity = opacity / 100;
el.style.filter = 'alpha(opacity = '+opacity+')';
_eff_fade_store[id]['frame'] = frame;
if(frame == 0) {
var tmp = _eff_fade_store[id]['callback'];
if(_eff_fade_store[id]['action'])
_eff_fade_store[id]['action'](el);
// garbage collector works?
_eff_fade_store[id] = undefined;
clearInterval(interval);
// call callback _after_ the fader stuff have been deleted
if(tmp) { tmp(); }
}
}
|