View Full Version : How to stop this Slideshow after 1 cycle?

09-22-2005, 03:18 AM
Here is a quick one. I have a great little slideshow script that I use, but it cycles indefinitely. I need it to cycle through once and then stop. What do I need to change and why? Here is the script in its entirety:

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 3000;
// Duration of crossfade (seconds)
var crossFadeDuration = 3;
// Specify the image files

var Pic = new Array();
Pic[0] = 'nickelbys/LOUNGE1.jpg'
Pic[1] = 'nickelbys/LOUNGE2.jpg'
Pic[2] = 'nickelbys/LOUNGE3.jpg'

// do not edit anything below this line
var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
preLoad[i] = new Image()
preLoad[i].src = Pic[i]

function runSlideShow(){
if (document.all){
document.images.SlideShow.src = preLoad[j].src
if (document.all){
j = j + 1
if (j > (p-1)) j=0
t = setTimeout('runSlideShow()', slideShowSpeed)

Thank you for any of your help, theMind-

09-22-2005, 06:41 AM
Change this:

if (j > (p-1)) j=0

to this:

if (j > (p-1)) return;

Why? Well, when j is greater than the number of pictures minus one, all pictures have been viewed once. In the original code, this signaled a restart at zero for j but, you say you want the thing to end at that point. Using return; in a function exits it.