Software Technology Tips

The following Javascript code will help you change the background-color of your web-page automatically and at a time-interval (in milli-seconds) as specified in the code.
 
<head>
<script type="text/javascript" language="javascript">
 
 
/* Method To Generate Random Numbers Between "0-255" for RGB Color-code Format & Assign To Body-Backgrond-Style */
 
function bgDisco()
{
var  x =Math.round(255*Math.random());

var num1 =getHex(x);

var  y =Math.round(255*Math.random());

var num2 =getHex(y);

var  z =Math.round(255*Math.random());

var num3 =getHex(z);

document.body.style.background="#"+num1+num2+num3;

setTimeout("bgDisco()",1000);
}
 
/* Method To Convert  Decimal To Hexadecimal */

function getHex(dec)
{
var hexArray = new Array( "0", "1", "2", "3","4", "5", "6", "7","8", "9", "A", "B","C", "D", "E", "F" );
 
var code1 = Math.floor(dec / 16);
 
var code2 = dec - code1 * 16;
 
var decToHex = hexArray[code2];
 
return (decToHex);
}
</script>
</head>
 
 
 
Now on the body part call the "bgDisco()" in onload event.
 
<body onload="bgDisco()">


Related Tags:

JavaScript

Author: Soumya Panda

JavaScript

Let us Connect!

iso 9001 QA25 Red Herring STPI D&B Fastest Growing SME 2013 Award zinnov Nasscom

copyright (c) Mindfire Solutions 2007-2014. Login