Results 1 to 3 of 3

Thread: Timer

  1. #1
    Join Date
    Dec 1969

    Default Timer

    Hi guys<BR><BR>I have a function HideMenu() that I want to get called when I onmouseout.<BR><BR>My idea is to leave 3 secs before it performs HideMenu(MenuBar).<BR><BR>This is what I have so far with no luck:<BR><BR>menuItem.onmouseout = new Function("timeoff()")<BR> <BR>//Part of a navigation bar I set up. It works with HideMenu(menuBar) but too quick, so I add the timer timeoff() <BR><BR>function timeOff()<BR> { <BR> window.setInterval("HideMenu(menuBar)", 100) <BR> } <BR><BR>when I call timeOff() it gives me the error.<BR><BR>Any help or tutorials are appreciated.<BR><BR>Thanks<BR>Don

  2. #2
    Join Date
    Dec 1969

    Default Erm, setTimeout()

    That&#039;s the wrong function. setInterval() is supposed to make a function run periodically, with a delay between each cycle.<BR><BR>setTimeOut() is a more appropriate function. It is functionally equivilant to running eval() with a time delay.<BR><BR>example: window.setTimeout(aFunction, aWaitTime)<BR><BR>So your function would be:<BR><BR>function timeOff()<BR>{ <BR>window.setTimeout("HideMenu(menuBar)", 3000) // use 3000 for 3 secs <BR>}

  3. #3
    Join Date
    Dec 1969

    Default can't use new Function...

    ...like that!<BR><BR>You just asked to create a *SECOND* function named "timeOff()"!<BR><BR>In JS code, you simply write:<BR> menuItem.onmouseout = timeoff;<BR><BR>No parens, at all.<BR><BR>But the disadvantage of doing this is that you can NOT pass any arguments to the function. It&#039;s a lot more flexible to write it in the HTML:<BR> &#060;DIV onMouseOut="timeOff( );"&#062;<BR><BR>Granted, in this case you don&#039;t have a parameter. But suppose you wanted to pass the time interval to the timeOff function:<BR> &#060;DIV onMouseOut="timeOff(3000);"&#062;<BR><BR>Or, even easier, you could simply do:<BR> &#060;DIV ID="menuBar" onMouseOut="setTimeout(&#039;HideMenu(menuBar)&#03 9;,3000);"&#062;<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts