Can't stop my slideshow (buggy)

A

Adrian MacNair

Hi I need some help if anyone can understand my crap javascript. The problem
is that after the slideshow ends (reaches the end of array) it should stop,
but the timeout doesn't clear and I can see the layer flashing.

I wrote a slideshow script. When you click a hypertext link it calls the
function speed() and passes the variable 5000:

var myvar = 0;
// Starting variable at zero
var myTimeout;
// Name of my Timeout
var running = false;
// variable for status of slideshow

function speed(x) {
// x could be 5000, 3000, or 1000 in milliseconds
if (running) {
// This is necessary to change the speed of the slideshow
running=false;
// stop running
clearTimeout(myTimeout);
};
// Now to restart the speed
if (!running) {
running=true;
nextimg(x);
};
}

function nextimg(x) {
// Change image to variable from array
// myImages is an array not included here. There are 63 images in the array.
document.getElementById('gallimg').src = myImages[myvar];
// increase variable by 1
myvar++;
// If we've reached the end of the images
if (myvar==63) {
// go to the stop function
stop()
};
// otherwise let's set a timeout to do it again
// Pass the variable x to nextimg() in x seconds
myTimeout = setTimeout("nextimg("+x+")",x);
}

function stop() {
running=false;
clearTimeout(myTimeout);
};
 
M

multimatum2

Adrian MacNair said:
Hi I need some help if anyone can understand my crap javascript. The
problem
is that after the slideshow ends (reaches the end of array) it should
stop,
but the timeout doesn't clear and I can see the layer flashing.

I wrote a slideshow script. When you click a hypertext link it calls the
function speed() and passes the variable 5000:

var myvar = 0;
// Starting variable at zero
var myTimeout;
// Name of my Timeout
var running = false;
// variable for status of slideshow

function speed(x) {
// x could be 5000, 3000, or 1000 in milliseconds
if (running) {
// This is necessary to change the speed of the slideshow
running=false;
// stop running
clearTimeout(myTimeout);
};
// Now to restart the speed
if (!running) {
running=true;
nextimg(x);
};
}

function nextimg(x) {
// Change image to variable from array
// myImages is an array not included here. There are 63 images in the
array.
document.getElementById('gallimg').src = myImages[myvar];
// increase variable by 1
myvar++;
// If we've reached the end of the images
if (myvar==63) {
// go to the stop function
stop()
};
// otherwise let's set a timeout to do it again
// Pass the variable x to nextimg() in x seconds
myTimeout = setTimeout("nextimg("+x+")",x);
}

function stop() {
running=false;
clearTimeout(myTimeout);
};


you were not far from the answer... Just have a look

function nextimg(x) {
document.getElementById('gallimg').src = myImages[myvar];
myvar++;

// If we've reached the end of the images

if (myvar==63) {
// go to the stop function
stop();
};
// otherwise let's set a timeout to do it again
// Pass the variable x to nextimg() in x seconds
ELSE
myTimeout = setTimeout("nextimg("+x+")",x);
}

as you say... OTHERWISE...
Just need a else

A+

Multimatum2
 
A

Adrian MacNair

multimatum2 said:
you were not far from the answer... Just have a look

function nextimg(x) {
document.getElementById('gallimg').src = myImages[myvar];
myvar++;

// If we've reached the end of the images

if (myvar==63) {
// go to the stop function
stop();
};
// otherwise let's set a timeout to do it again
// Pass the variable x to nextimg() in x seconds
ELSE
myTimeout = setTimeout("nextimg("+x+")",x);
}

as you say... OTHERWISE...
Just need a else

Many thanks my friend.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top