Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Need help with a drop-down menu

  1. #1
    Join Date
    Mar 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with a drop-down menu

    Hello from Latvia!!! I'm having a problem with upgrading a small drop-down-menu script which I have put here: http://paste.php.lv/3480. The problem is that when I get onmouseout function, the sub-menus immediately dissapear, my question is this: how can I make the sub-menus stay 1 second after the mouse got from the sub-menu off. I know that I somehow have to use function timer(); but I can't understand, how to connect it together with the code. Previously thanks, and sorry for the bad language.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
     <script type="text/javascript">
     function getElementNumber(el) {
       var els = document.getElementsByTagName(el.tagName);
       for(var i=0;i<els.length;i++) if(els[i] == el) return i;
       return -1;
     }
    
     over = function() {
         var sfEls = document.getElementById("nav").getElementsByTagName("LI");
         for (var i=0; i<sfEls.length; i++) {
             sfEls[i].onmouseover=function() {
                 this.className+=" over";
             }
             sfEls[i].onmouseout=function() {
                 var me = getElementNumber(this);
                 window.clearTimeout(this.closeTimer);
                 this.closeTimer = window.setTimeout("document.getElementsByTagName('LI')["+me+"].className=document.getElementsByTagName('LI')["+me+"].className.replace(/over\b/, '')";
             }
         }
     }
     if (window.attachEvent) window.attachEvent("onload", over);
     else window.onload = over;
     </script>
    Untested.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry but it doesn't work, it doesn't even display the sub-menus in IE with this code, only in FF (the browsers that I tested) :[

  4. #4
    Join Date
    Mar 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Maybe the functions setInterval() & clearInterval() should help, as I understand, they're something like the timer function!

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    PLEASE: Include the URL to your problematic webpage that you want help with.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Mar 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well I have put the version before editing something as you said here: http://www.lfka.lv/index2.htm and the code is here: http://paste.php.lv/3480 (the navigation is changed, I mean the html part, but I left css and js untouched)

    The edited version could be found here: http://www.lfka.lv/index3.htm and the code is here: http://paste.php.lv/3484

    As you can see, your variant doesn't work as thougt, as well as sub-menus don't work in IE at all.
    Last edited by keissfootball; 03-22-2006 at 07:37 AM.

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I'm sorry. Change this line:
    Code:
                 this.closeTimer = window.setTimeout("document.getElementsByTagName('LI')["+me+"].className=document.getElementsByTagName('LI')["+me+"].className.replace(/over\b/, '')", 300);
    Add the bits in red, where 300 is the delay in milliseconds.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Mar 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have to admit that I already tried this, only longer delay - 3000, but the edited code still doesn't show up the sub-menus, and the delay doesn't work in FF, neither can I check it in the IE, because of " not showing sub-menu" problem! :[

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Please add it to the "edited" page so I can see.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Mar 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    All done (http://www.lfka.lv/index3.htm), I had a small mistake, so it didn't work, but now, the menu's acting really strange, in both browsers, see for yourself, that it leaves the sub-menus on each other, and the sub-menus don't dissapear!
    Last edited by keissfootball; 03-21-2006 at 09:42 PM.

Bookmarks

Posting Permissions

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