Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2234
  • Last Modified:

reset setTimeout

I am using this javascript code:

function delayhidemenu() {
     setTimeout("hideall()",5000)
}

This code will hide some html code after 5 seconds.
It works fine.

But is it possible to reset/disable the settimeout after it has been set. I use the code when I move the mouse from a link -> like this: onmouseout="delayhidemenu()".

However when I go over the link again in the 5 seconds the html text will be still hidden after the 5 seconds!
That is not what I want it to be!

Can this be done?
0
draco51
Asked:
draco51
  • 3
1 Solution
 
knightEknightCommented:
set your timeout like this:


   var myTimoutID = setTimeout("hideall()",5000);



then clear it like this:

   clearTimeout(myTimoutID);

0
 
knightEknightCommented:
... just make sure that the variable myTimeoutID is global in scope (i.e., not local to the function that calls setTimeout).
0
 
knightEknightCommented:
like this:


var myTimeoutID;

function delayhidemenu() {
    if (myTimeoutID)
       clearTimeout(myTimeoutID);
    myTimeoutID = setTimeout("hideall()",5000);
}
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now