Christiane
05-14-2010, 10:26 AM
Hello, I don't know much about JavaScript but am trying to build a random image rotator that displays a different image every time the page loads but also depends on the season or month (if that's easier). I found this script online and it works fine in general:
var imageArray = new Array();
imageArray[0] = "spring1.jpg";
imageArray[1] = "spring2.jpg";
imageArray[2] = "spring3.jpg";
imageArray[3] = "spring4.jpg";
function doIt() {
var rand = Math.floor(Math.random() * 4);
var imgPath = "<img src='" + imageArray[rand] + "' alt='heder' border='0' align='absmiddle' />";
document.getElementById("seasonal").innerHTML = imgPath;
}
Is it possible to have 4 folders (spring, summer, autumn, winter) with different images and then call a function that first checks what season it is and then displays the images for the right season/ from the right folder at random?
var imageArray = new Array();
imageArray[0] = "spring1.jpg";
imageArray[1] = "spring2.jpg";
imageArray[2] = "spring3.jpg";
imageArray[3] = "spring4.jpg";
function doIt() {
var rand = Math.floor(Math.random() * 4);
var imgPath = "<img src='" + imageArray[rand] + "' alt='heder' border='0' align='absmiddle' />";
document.getElementById("seasonal").innerHTML = imgPath;
}
Is it possible to have 4 folders (spring, summer, autumn, winter) with different images and then call a function that first checks what season it is and then displays the images for the right season/ from the right folder at random?