...

View Full Version : Random graphic with a twist - help please



cbouchar
03-26-2005, 02:10 PM
I would like to have my header graphic change randomly, without ssi. Doing a search of the forums, I found this post:
http://www.codingforums.com/showthread.php?t=42514

That script, shown below, is exactly what I need BUT, I need to modify it and I am not sure how. My header graphic is quite large and I want to slice it up into several peices. How can I load a random header when the header is broken into several smaller graphics - I need the 4 peices to all match!




<script language="JavaScript" type="text/javascript">
// This script was supplied free by Hypergurl
// http://www.h y p e r g u r l .com remove the spaces
<!--
// JavaScript to interpolate random images into a page.
var ic = 6; // Number of alternative images
var xoxo = new Array(ic); // Array to hold filenames

xoxo[0] = "http://www.yoursite.com/graphic1.gif";
xoxo[1] = "http://www.yoursite.com/graphic2.gif";
xoxo[2] = "http://www.yoursite.com/graphic3.gif";
xoxo[3] = "http://www.yoursite.com/graphic4.gif";
xoxo[4] = "http://www.yoursite.com/graphic5.gif";
xoxo[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 an IMG tag, using a randomly-chosen image name.
var choice = pickRandom(ic);
// -->
</script>





<SCRIPT LANGUAGE="JavaScript">document.writeln('<TD'+'><IMG SRC="'+xoxo[choice]+'" HEIGHT=184 WIDTH=120 BORDER=0 ><'+'/TD>');</SCRIPT>


Any help would be appreciated,

cbouchar

vwphillips
03-26-2005, 03:17 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
// by Vic Phillips http://www.vicsjavascripts.org.uk


var ImgPath='http://www.vicsjavascripts.org.uk/StdImages/';

var ImgAry = new Array(); // Array to hold filenames
ImgAry[0] = ['Zero.gif','One.gif','Two.gif'];
ImgAry[1] = ['One.gif','Two.gif','Three.gif'];
ImgAry[2] = ['Two.gif','Three.gif','Four.gif'];
ImgAry[3] = ['Three.gif','Four.gif','Five.gif'];

set=Math.floor(Math.random()*ImgAry.length)

function LoadDisplay(){
for (i=0;i<3;i++){
document.getElementById('MyImg'+i).src=ImgPath+ImgAry[set][i];
}
}

// -->
</script>
</head>

<body onload="LoadDisplay();" >


<img id="MyImg0" src="Blank.gif" width="50" height="50"><img id="MyImg1" src="Blank.gif" width="50" height="50"><img id="MyImg2" src="Blank.gif" width="50" height="50">
</body>

</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum