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);
};
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);
};