Home >Web Front-end >JS Tutorial >Automatic background color changing code implemented in JavaScript_javascript skills
The example in this article describes the automatic background color changing code implemented in JavaScript. Share it with everyone for your reference, the details are as follows:
Here is a demonstration of JavaScript to automatically change the color of the web page background. You can change the color yourself and set the time and color value. It will automatically switch the web page background color within the color value you set and within a certain period of time.
The screenshot of the running effect is as follows:
The online demo address is as follows:
http://demo.jb51.net/js/2015/js-auto-cha-bg-color-demo/
The specific code is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>背景自动变色</title> </head> <body> 背景自动变色 <script language="javascript"> var Arraycolor=new Array("#00FF66","#FFFF99","#99CCFF","#FFCCFF","#FFCC99","#00FFFF","#FFFF00","#FFCC00","#FF00FF"); var n=0; function turncolors(){ n++; if (n==(Arraycolor.length-1)) n=0; document.bgColor = Arraycolor[n]; setTimeout("turncolors()",1000); } turncolors(); </script> </body> </html>
I hope this article will be helpful to everyone in JavaScript programming.