| re: Can't stop my slideshow (buggy)
"Adrian MacNair" <amacnairDONT@SPAMsympaticoME.ca> a écrit dans le message
de news: lOXie.3731$Wp.564017@news20.bellglobal.com...[color=blue]
> 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);
> };
>
>[/color]
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 |