Home >Web Front-end >JS Tutorial >JS method to realize gradient background color when entering the page_javascript skills

JS method to realize gradient background color when entering the page_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:13:101971browse

The example in this article describes the method of JS to realize the gradient background color when entering the page. Share it with everyone for your reference. The specific implementation method is as follows:

<html>
<head>
<title>JS实现的进入页面时的渐变的背景色效果</title>
<SCRIPT Language="JavaScript">
<!-- 屏幕变色程序 -->
function CBgColor(){
var color = 0, step = 1
//color为初始颜色,step为初始步长
while( color <= 0xffffff){
//在颜色变白(color=0xffffff)之前,不断将颜色值增加
document.bgColor = color
color += step  
step <<= 8
//步长按位左移8位(乘以256)
if( step >= 0x1000000) step = 1
//如果步长过大则将其恢复到1
}
}
CBgColor()
//装入时调用背景变色程序
</Script>
</head>
<body onLoad="CBgColor()">
<p><b>渐变的背景颜色,感觉不错吧?</b></p>
</body>
</html>

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn