Stefan Weiss <krewech
...@gmail.com> wrote:
>On 2012-10-09 19:35, joe wrote:
>> Here's full working example of a vertical menu with sublevels. Whar I am trying
>> to achive is a time.out from the menu. ie when mouse-cursor leaves the menu item
>> it should not immediately disappear - it shout stay a 1000 msecs before
>> disappearing. My efforts with setTimeout are unsuccessfull.
>> In the code there is
>> ul_level[i].parentNode.onmouseout=function()
>> {this.getElementsByTagName("ul")[0].style.display="none";}
>When you post code on Usenet, please keep your lines short enough to
>prevent unintentional wrapping.
>> which I trying to delay a little. Unfortunately
>> ul_level[i].parentNode.onmouseout=function() {
>> timou=setTimeout(function() {
>> this.getElementsByTagName("ul")[0].style.display="none";},1000); }
>> does not work. The menu just stays and does not go away after 100 msecs.
>You might have mentioned that you also get an error message at this
>point: "TypeError: Object [object Window] has no method
>'getElementsByTagName'".
>If you didn't get an error message, search the web for how to enable JS
>debugging in your browser. There should also be something in the FAQ
>about debuggers.
>When the timeout fires and your inner function is executed, "this"
>refers to the global object. You wanted it to refer to one of your menu
>elements, but that reference is gone now. You have to store the "this"
>value somewhere, so that the element reference is still available when
>the function is called:
>ul_level[i].parentNode.onmouseout = function() {
> var that = this;
> setTimeout(function() {
> that.getElementsByTagName("ul")[0].style ...
> }, 1000);
>}
>From what I've seen, you also need to add some code to clear the
>timeouts when the user moves between menu items.
>- stefan