Solved

reset setTimeout

Posted on 2002-03-17
3
2,214 Views
Last Modified: 2012-06-27
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
Comment
Question by:draco51
  • 3
3 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 6874399
set your timeout like this:


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



then clear it like this:

   clearTimeout(myTimoutID);

0
 
LVL 33

Expert Comment

by:knightEknight
ID: 6874404
... just make sure that the variable myTimeoutID is global in scope (i.e., not local to the function that calls setTimeout).
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 200 total points
ID: 6874422
like this:


var myTimeoutID;

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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now