/
script.js
55 lines (36 loc) · 1.25 KB
/
script.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
window.onload = function(){
var objeto = document.getElementById('objeto');
document.getElementById("fadeIn").onclick = function(){
fadeIn(objeto,1);
}
document.getElementById("fadeOut").onclick = function(){
fadeOut(objeto,1);
}
}
function fadeIn(element,time){
processa(element,time,0,100);
}
function fadeOut(element,time){
processa(element,time,100,0);
}
function processa(element,time,initial,end){
if(initial == 0){
increment = 2;
element.style.display = "block";
}else {
increment = -2;
}
opc = initial;
intervalo = setInterval(function(){
if((opc == end)){
if(end == 0){
element.style.display = "none";
}
clearInterval(intervalo);
}else {
opc += increment;
element.style.opacity = opc/100;
element.style.filter = "alpha(opacity="+opc+")";
}
},time * 10);
}