Forum Moderators: open

Message Too Old, No Replies

Rnd Display 7 Images from a Dir

also make them change every few second AUTO

         

CIAimages

10:12 am on Nov 28, 2004 (gmt 0)

10+ Year Member



I have the cool script I use on my site that display 7 pictures at Rnd and every 0.5 sec a pic changes now it is supposed to take the pics from a dir where I have over 25 pics and use allof them in Rnd but for some raison it uses only one and use the same all the time.

every time I reload the page it use a different pic but it's gonna use that pic as long as the page is loaded does it make sence?

any way ere is the code

Also I was getting an error from time to time so I had to create a pic with the name "-1.gif"

<SCRIPT language=javascript type=text/javascript>
//total image files
nTotal=26;

var pix = new Array();
var urlbase = 'http://localhost';
var pixidx = 0;

for (var i=0; i < 0; i++) {
r = Math.round(Math.random() * (nTotal-1));
pix[pixidx++] = urlbase + "/images/marquee/bw/" + r + ".gif";
}

for (var i=0; i < 9; i++) {
r = Math.round(Math.random() * (nTotal-1));
pix[pixidx++] = urlbase + "/images/marquee/bw/" + r + ".gif";
}

// getUniqueImage()
// Returns an index for the pix[] array that (probably) contains a unique image
function getUniqueImage()
{
for (var j=0; j<pix.length; j++) {
duplicate = false;
for (var i = 1; i < 9; i++)
{
if(document.images[i].src.indexOf(pix[j])!= -1)
{
duplicate=true;
}
}
if (!duplicate) {
return j;
}
}

// Couldn't find a non-duplicate so pick one at random
numRandom=Math.round(Math.random() * (pix.length - 1));
return numRandom;
}

function changeAuto()
{
indSrc = getUniqueImage();
indImg = Math.round(Math.random()*7)+1;
tmp = document.images[indImg].src;
document.images[indImg].src = pix[indSrc];
pix[indSrc] = tmp;
delay = 500;
setTimeout("changeAuto()", delay);
}

// Now make sure changeAuto() gets called on loading.
window.onload = changeAuto;
</SCRIPT>

DrDoc

9:24 pm on Nov 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...
for (var i=0; i < 0; i++)
...

I'm sure that's not what you want. If you want seven images, try this instead:

for (var i=0; i < 7; i++)