javascript網頁背景顏色漸變效果

antzone發表於2017-04-06

本章節分享一段簡單程式碼例項,它實現了網頁背景顏色漸變效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.51texiao.cn/" />
<title>螞蟻部落</title>
<style>
a:hover{
  color:#00FFFF
}
</style>
<script>
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);
  }
}
window.onload=function(){
  fadeIn(15)
}
</script>
</head>
<body>
<div>>http://www.softwhy.com</div>
</body>
</html>

相關文章