BLiZZaRD
02-29-2008, 07:40 PM
Hey I have a tiny little rotating/randomizing js file that works really really well.
See it here:
divs = ['d1','d2','d3','d4','d5'];
function hideDivs() {
for (var i=0; i<divs.length; i++)
document.getElementById(divs[i]).style.display = 'none';
}
function showDiv() {
hideDivs(); //hide them all before we show the next one.
var randomDiv = divs[Math.floor(Math.random()*divs.length)];
var div = document.getElementById(randomDiv).style.display =
'block';
setTimeout(showDiv,8000); //set a delay before showing the next div
}
Told you it was tiny.
Now basically what this does is it takes specific divs in my html and hides them, then picks one at random and displays it, rotate, repeat. Like I said, it works great.
The problem? I don't want it to be random any more. I just want it to scroll through the divs one at a time and display them then start over at 1 when it reaches the end.
What do I re-write to make it stop being random? I know WHERE, I just don't know HOW. Everything I have tried breaks it all together.
Help?
See it here:
divs = ['d1','d2','d3','d4','d5'];
function hideDivs() {
for (var i=0; i<divs.length; i++)
document.getElementById(divs[i]).style.display = 'none';
}
function showDiv() {
hideDivs(); //hide them all before we show the next one.
var randomDiv = divs[Math.floor(Math.random()*divs.length)];
var div = document.getElementById(randomDiv).style.display =
'block';
setTimeout(showDiv,8000); //set a delay before showing the next div
}
Told you it was tiny.
Now basically what this does is it takes specific divs in my html and hides them, then picks one at random and displays it, rotate, repeat. Like I said, it works great.
The problem? I don't want it to be random any more. I just want it to scroll through the divs one at a time and display them then start over at 1 when it reaches the end.
What do I re-write to make it stop being random? I know WHERE, I just don't know HOW. Everything I have tried breaks it all together.
Help?