Connecting Tech Pros Worldwide Forums | Help | Site Map

Can't stop my slideshow (buggy)

Adrian MacNair
Guest
 
Posts: n/a
#1: Jul 23 '05
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);
};



multimatum2
Guest
 
Posts: n/a
#2: Jul 23 '05

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




Adrian MacNair
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Can't stop my slideshow (buggy)


"multimatum2" <multimatum2@voila.fr> wrote in message
news:1116503635.21011.0@lotis.uk.clara.net...[color=blue]
> 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[/color]

Many thanks my friend.


Closed Thread


Similar JavaScript / Ajax / DHTML bytes