Click to See Complete Forum and Search --> : Image slide show


Ninel
03-20-2003, 10:23 AM
I am using the following code for an image slideshow:

<body BGCOLOR="#000000" text="#CCCCCC" link="#CC9933" vlink="#999966" alink="#FFCC33" onload="doLink">

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<SCRIPT LANGUAGE="JavaScript">
<!--
//set image paths
src = ["images/Pic1.jpg", "images/Pic2.bmp", "images/Pic3.jpg"]
//set duration for each image
duration = 2;
ads=[]; ct=0;
function switchAd()
{
var n=(ct+1)%src.length;
if (ads[n] && (ads[n].complete || ads
[n].complete==null))
{
document["Ad_Image"].src = ads[ct=n].src;
}
ads[n=(ct+1)%src.length] = new Image;
ads[n].src = src[n];
setTimeout("switchAd()",duration*600);
}
function doLink(){
} onload = function(){
if (document.images)
switchAd();
}
//-->
</SCRIPT>

<IMG NAME="Ad_Image" SRC="images/Pic1.jpg" BORDER=0 width="150" length="120">

Although the images do change at some point, they don't begin changing when the page just loads.
Is there something that I need to change in the code to have the images flip as soon as the page loads?

Here's the website:
www.MonarchMedical.com

Thanks,
Ninel

cyberade
03-20-2003, 11:03 AM
Two suggestions:

1) Move your <script> code into the <head> section
2) Preload your images
var img0 = new Image();
img0 = "images/image_zero.jpg";
var img1 = new Image();
img1 = "imagesimage_one.jpg"; etc...

If you do that remember to update 'src' to point to the image variables.

Ninel
03-20-2003, 01:51 PM
I placed code in the <head> tag, but it still takes a long time to initially load the images.

Am I doing this correctly?

Jona
03-20-2003, 01:57 PM
Your images will always take a while to load. After, however, they are preloaded it doesn't take as long to go through the slideshow.

Ninel
03-20-2003, 02:10 PM
Why will they take a long time to load?
Did I preload them properly?

Jona
03-20-2003, 02:11 PM
Yeah. But it takes a long time for them to load, then the page loads, but the images are already loaded. That's how preloading works. It just makes it faster, although it takes some time to load in the first place.

Ninel
03-20-2003, 02:34 PM
So, you are saying that I wrote my code properly and that it will always take that long to load the images initially?

Jona
03-20-2003, 02:35 PM
Of course! The images has a size, and it has to be loaded somewhere along the line. But when preloaded, the slideshow moves faster. So it takes a while to preload them, but after they're preloaded you don't have to reload each image over and over again every time you run the slideshow.

Ninel
03-20-2003, 02:38 PM
Well that sucks!!!

Vladdy
03-20-2003, 02:41 PM
Do not preload images with the page. Allow the page to load, then load your first image, start the slide-show, then continue loading the rest of images in the background:
http://www.vladdy.net/webdesign/slideshow.html