View Full Version : multiple background images
larry2c
05-31-2005, 01:05 PM
Before anyone accuses me of it, I'll just admit it. I am pretty much a rookie at web design, but my boss has assigned me the task of maintaining our internal website and so here I am. To dress things up a bit, I want to have a background image that would be different each time the page is loaded.
Can some one give me some advice on how to do that?
Thanks in advance
:thumbup:
_Aerospace_Eng_
05-31-2005, 01:22 PM
If you are wanting the background image to be random onload you can use this script. It writes out the css for a background image randomly. It has 6 choices to choose from. This can be changed by changing the ic value to another number just be sure to add on the other images in a similar fashion.
<!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=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
<!--
// JavaScript to interpolate random background images into a page.
var ic = 6; // Number of alternative background images
var bgimg = new Array(ic); // Array to hold filenames
bgimg[0] = "http://www.yoursite.com/graphic1.gif";
bgimg[1] = "http://www.yoursite.com/graphic2.gif";
bgimg[2] = "http://www.yoursite.com/graphic3.gif";
bgimg[3] = "http://www.yoursite.com/graphic4.gif";
bgimg[4] = "http://www.yoursite.com/graphic5.gif";
bgimg[5] = "http://www.yoursite.com/graphic6.gif";
function pickRandom(range) {
if (Math.random)
return Math.round(Math.random() * (range-1));
else {
var now = new Date();
return (now.getTime() / 1000) % range;
}
}
// Write out css body background property, using a randomly-chosen backgroun image name.
var choice = pickRandom(ic);
document.write('<style type="text/css">');
document.write('body {background-image:url('+bgimg[choice]+');');
document.write('</style>');
// -->
</script>
</head>
<body>
Your content here
</body>
</html>
larry2c
05-31-2005, 01:45 PM
Thanks for the quick response. Today I'm home finishing the weekends chores, but tomorrow, I will insert your script and give it a try. Thanks for the help
By the way, I to am an Aerospace Engineer. I work in the Enabling Technologies department at Goodrich Aerostructures Group. Some times it's an extremely small world.
=:O
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.