Hi Folks,
I’m hoping somebody can help me out here.
I’d like my index page to have a random background image underneath
my text, log in boxes etc.
So, I’ve got a working script inserted into the HTML header like so…
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
{%PageMetadataMacro%}
[COLOR="Red"]<script type="text/javascript" language="JavaScript">
NumberOfImagesToRotate = 5;
// Specify the first and last part of the image tag.
FirstPart = '<img src="/images/testran';
LastPart = '.png" height="486" width="983">';
function printImage() {
var r = Math.ceil(Math.random() * NumberOfImagesToRotate);
document.write(FirstPart + r + LastPart);
}
//-->
</script>[/COLOR]
{%PageMetadataMacro%}
</head>
<body>
<div class="holder" id="header">
<div class="content">
{%HeaderMacro%}
{%SiteSloganMacro%}
{%SwitchLocaleMacro%}
{%LoginMacro%}
</div>
</div>
<div class="holder" id="main">
<div class="content">
<div id="body">
<div class="column" id="left">{%QuickSearchMacro%}</div>
<div class="column" id="right"><h1><strong>{%ONLINE_MEMBERS_COUNT%}</strong><span class="status online">online</span><br />users</h1></div>
</div>
{%MembersNewMacro%}
</div>
</div>
<div class="holder" id="footer">
<div class="content">
{%FooterMacro%}
{%PageTrackingCodeMacro%}
</div>
</div>
</body>
</html>
The code for the script to activate is nice and simple, like so…
<script type="text/javascript" language="JavaScript"><!--
printImage();
//--></script>
Which is all well and good, and will work if I put the actual script link
in the body section of the html. However, I want the images to be my background rather than just inserting them into the page between stuff.
At the moment the background is controlled via the relevant bit of CSS, which is currently written up as :
div#body {width:983px; background:url(/images/testran1.png)left top no-repeat; height:486px}
div#body div.column {display:block;}
div#body div#left.column {float:left; width:340px}
div#body div#right.column {float:right; width:225px; padding-right:20px; padding-top:15px}
So where the default background is /images/testran1.png above,
I’d like to change it so it references the script so it will load random images.
I’ve tried a few things and I’m not getting much luck.
Any help ?