Hi Folks,
I'll show you my code first:
I am trying to do the following:
1. Preload all the images that I require for this particular HTML page.
2. Every five seconds change 5 images on the page to the next one in the sequence.
I have tried to use the setTimeOut to do this but I see the flaw in my script. I have a loop setup which calls the setTimeout with a delay of 5 seconds. But I understand that it does the four calls almost simultaneously.
When the page loads I need to wait 5 seconds and then call the swapAllImages function, then wait another 5 seconds and call it again - all the while looping through the image arrays.
I also need to encompass that whole thing is a while loop so that it goes through that process continually while the page is open.
Any suggestions on how I can do all that would be greatly appreciated.
My second problem is what while this crossfade function is brilliant, it will only work on one image - can't seem to change more than one image at the same time. Can anyone recommend a way to fade in another image on 5 images at the same time.
Mighty
I'll show you my code first:
Code:
<!-- Preload the images -->
if (document.images)
{
// Declare array to store images
var mainArray = new Array(5);
var squareArray = new Array(5,4);
// Loop through and add all the images
for (i = 0; i < 5; i++) {
// Load the main images
mainArray[i]= new Image(534,235);
mainArray[i].src="/images/home/main" + (i + 1) + ".jpg";
// Load the square images
for (j = 0; j < 4; j++) {
squareArray[i,j]= new Image(116,116);
squareArray[i,j].src="/images/home/square" + (i + 1) + "_" + (j + 1) + ".jpg";
}
}
}
// This function changes the images on the page
function swapImages()
{
for (i = 0; i < mainArray.length; i++) {
timer = setTimeout("swapAllImages(" + i + ")", 5000);
}
}
function swapAllImages(imgNum)
{
// Change the main image
crossfade(document.getElementById('main'), mainArray[img]um[/img].src, '3', 'Main Image ' + imgNum);
// Change the 4 square images
crossfade(document.getElementById('square1'), squareArray[img]um, 0[/img].src, '3', 'Square Image ' + (imgNum + 1) + "_1");
crossfade(document.getElementById('square2'), squareArray[img]um, 1[/img].src, '3', 'Square Image ' + (imgNum + 1) + "_2");
crossfade(document.getElementById('square3'), squareArray[img]um, 2[/img].src, '3', 'Square Image ' + (imgNum + 1) + "_3");
crossfade(document.getElementById('square4'), squareArray[img]um, 3[/img].src, '3', 'Square Image ' + (imgNum + 1) + "_4");
}
I am trying to do the following:
1. Preload all the images that I require for this particular HTML page.
2. Every five seconds change 5 images on the page to the next one in the sequence.
I have tried to use the setTimeOut to do this but I see the flaw in my script. I have a loop setup which calls the setTimeout with a delay of 5 seconds. But I understand that it does the four calls almost simultaneously.
When the page loads I need to wait 5 seconds and then call the swapAllImages function, then wait another 5 seconds and call it again - all the while looping through the image arrays.
I also need to encompass that whole thing is a while loop so that it goes through that process continually while the page is open.
Any suggestions on how I can do all that would be greatly appreciated.
My second problem is what while this crossfade function is brilliant, it will only work on one image - can't seem to change more than one image at the same time. Can anyone recommend a way to fade in another image on 5 images at the same time.
Mighty