Background effects - A cool JavaScript tip
Sponsored Links
Here is a cool Javascript tip that will change the background color over time. With a few modifications, you can use this tip to display all the colors of the rainbow in the background. This tip describes how to create a fading web page background.
If you missed it... click here to see the background color effect again.
Using the bgColor property of the JavaScript window object, we can change the background color. Here is the code:
var c = new Array("00", "11", "22", "33", "44", "55",
"66", "77", "88", "99", "AA", "BB", "CC", "DD", "EE", "FF");
x = 0;
function bg_eff()
{
col_val = "#FFFF" + c[x];
document.bgColor=col_val;
x++;
if (x == 16)
{
clearInterval(change_bg);
}
}
change_bg = setInterval("bg_eff()", 250);
The color values are stored in an array c. The function bg_eff() assigns a color value to variable col_val and then sets the bgColor property to this value. The function is called after every 250 milliseconds using the setInterval() method. On each call to the function the value of variable x is increased by one. When x equals 15, the clearInterval() method is invoked that stops the setInternval() method.
Page contents: Learn how to change the background color of a web page using this cool JavaScript tip. Change and configure the JavaScript code as per requirements.
Comments, questions, feedback... whatever!
Recent Articles
Recent Blog Posts
Popular Articles
- Hotmail Sign In page
- Create a Hotmail account - Instructions
- Create Gmail address
- Download and install Outlook Express
- Get your free Gmail address
- Outlook Express new version
- Create my own email address
- Browers for Windows list
- Get email address
- Color combinations for web sites and pages
- Create Yahoo ID
More web tips & tricks
- Outlook Express Help - tips & tricks (53)
- Windows Live Mail help and tips (36)
- Windows Mail help (25)
- Hotmail help and tips (42)
- Yahoo help & support (45)
- AOL email help (26)
- Gmail help and tips (36)
- Internet tips & tricks (12)
- Web Design tips & tricks (33)
- HTML, Javascript tips tricks (68)
- Web Promotion tips & tricks (8)
- Graphics tips & tricks (20)
