渐隐渐现fade js

function fadeIn(el){
el.style.opacity = 0;
el.style.filter = 'alpha(opacity = 0)';
el.style.display = 'block';
var n = 0;
function fadeShow(){
if (n < 1){
n += 0.1;
el.style.opacity = n;
el.style.filter = 'alpha(opacity = '+n*100+')';
var setTimeId = setTimeout(fadeShow, 50);
}else{
el.style.opacity = 1;
el.style.filter = 'alpha(opacity = 100)';
clearTimeout(setTimeId);
}
}
fadeShow();
}
function fadeOut(el){
el.style.opacity = 1;
el.style.filter = 'alpha(opacity = 100)';
var n = 1;
function fadeHide(){
if (n > 0){
n -= 0.1;
el.style.opacity = n;
el.style.filter = 'alpha(opacity = '+n*100+')';
var setTimeId = setTimeout(fadeHide, 50);
}else{
el.style.opacity = 0;
el.style.filter = 'alpha(opacity = 0)';
clearTimeout(setTimeId);
el.style.display = 'none';
}
}
fadeHide();
}
原文地址:https://www.cnblogs.com/bianyuan/p/2356660.html