js网页背景颜色效果:实现网页渐隐渐显背景颜色的方法

发布时间:2020-03-02编辑:脚本学堂
js如何控制网页背景颜色,用javascript实现网页渐隐渐显背景颜色的效果,将背景颜色值保存到js数组中,通过自定义的fadein与fadeout函数实现背景颜色的渐隐淡显效果。

javascript实现网页渐隐渐显背景颜色

代码:
 

复制代码 代码示例:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>javascript渐隐渐显的背景颜色 - www.jb200.com</title>
<style fprolloverstyle>A:hover {color: #00FFFF}
</style>
</head>
<body onLoad="fadeIn(15)">
<script language="javascript">
var Color= new Array("ff","ee","dd","cc","bb","aa","99","88","77","66","55","44","33","22","11","00");
function fadeIn(n) {
if (n >= 1) {
document.bgColor="#" +"00"+ Color[n] +"00";
n -= 1;
setTimeout("fadeIn("+n+")", 100);
}
else{setTimeout('fadeOut(1)', 100);}
}
function fadeOut(n) {
if (n <=(Color.length-1)) {
document.bgColor="#" +"00"+ Color[n] +"00";
n += 1;
setTimeout("fadeOut("+n+")", 100)
}
else{setTimeout("fadeIn("+(Color.length-1)+")", 100);}
}
</script>
<div>javascript实现的渐隐渐显的背景颜色 http://www.dgjs123.com/</div>
</body>
</html>