Home > Web Front-end > JS Tutorial > Automatic background color changing code implemented in JavaScript_javascript skills

Automatic background color changing code implemented in JavaScript_javascript skills

WBOY
Release: 2016-05-16 15:36:16
Original
2079 people have browsed it

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>

Copy after login

I hope this article will be helpful to everyone in JavaScript programming.

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template