Closed Thread Icon

Preserved Topic: how to stop a timeout? Pages that link to <a href="https://ozoneasylum.com/backlink?for=18061" title="Pages that link to Preserved Topic: how to stop a timeout?" rel="nofollow" >Preserved Topic: how to stop a timeout?\

 
Author Thread
Osaires
Paranoid (IV) Inmate

From: oslo, Norway
Insane since: Aug 2001

posted posted 08-07-2001 22:24

I have a script that move a line with the comand

function Move()
{
document.all.floater.style.pixelTop += 1;
setTimeout('move()',1);
}

how can i stop the motion?

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 08-07-2001 22:48

Define timer like this:

maxTimer = setTimeout('move()',1);

And use this to stop it:

clearTimeout(maxTimer);

Osaires
Paranoid (IV) Inmate

From: oslo, Norway
Insane since: Aug 2001

posted posted 08-07-2001 22:55

Thanks, inthink this will help

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-07-2001 23:26

Note that it's important to have the variable in a wide enough "scope" for it to be canceled later. For instance:

function setthetimer()
{
var mytimer = setTimeout('blah();',300);
}

function somethinghappened()
{
clearTimeout(mytimer);
}

That won't work! Because mytimer is defined in one function, and its forgotten about when the function ends. Instead, you must do something like this:


var mytimer;

function setthetimer()
{
mytimer = setTimeout('blah();',300);
}

function somethinghappened()
{
clearTimeout(mytimer);
}

In this case, mytimer is defined outside of the functions, so its not forgotten about.

« BackwardsOnwards »

Show Forum Drop Down Menu