Jump to content

setTimeout problem


reallysick
 Share

Recommended Posts

Hi,I have a menu with a submenu that I want to hide after 5 seconds.The submenu is a string that I hide and show on mouseOver and mouseOut.In mouseOver:

  var submenustring="";  for(i=0; i<AbsoluteArray[id-1].length; i++)  {    var x=document.getElementById('submenu').rows[0].cells;    x[0].style.padding="0px 0px 0px "+px+"px";    submenustring = submenustring + AbsoluteArray[id-1][i];    if(i<AbsoluteArray[id-1].length-1)    {      submenustring = submenustring + " | ";    }  }  x[0].innerHTML= submenustring;  document.getElementById("submenu").style.visibility = "visible";  count();

In my count() function, I call the setTimeOut javascript function to hide my submenu after 5 seconds

function count(){  var t = 0;  t=setTimeout('document.getElementById("submenu").style.visibility = "hidden"',5000);  clearTimeout(t);}

The problem is that the "timer" doesn't start at 0 on eachmouse over so the submenu disapears before the 5 seconds is completed. :) I want to have a 5 seconds submenu on each mouse overThanks !

Link to comment
Share on other sites

Have you tried making t a global variable so you can clear the timeout before setting it again?You might want to go ahead and have a function called "hideSub" or something and have it called on mouseout and when the timer goes off...Also... please don't use tables for layout!...It is just too easy do menus without tables!

Link to comment
Share on other sites

as far as horizontal menus go, take a look at the following pages if you get time and see if any of them are what you are looking forhttp://www.alistapart.com/articles/dropdowns (working example -> http://www.htmldog.com/articles/suckerfish/example/ )http://www.alistapart.com/articles/hybrid (working example -> http://www.alistapart.com/d/hybrid/hybrid-4.html )

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...