Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: DropDown Menu

  1. #1
    New Coder
    Join Date
    Sep 2011
    Location
    UK, South Wales, Newport
    Posts
    21
    Thanks
    8
    Thanked 0 Times in 0 Posts

    DropDown Menu

    Can someone please explain this code to me please. Its the beginning of a javascript code to hide and show a drop down menu. Ill include the html code to give u a better understanding too. Thank you so much, ive been frustrated on this for nearly a month

    HTML
    Code:
    <body> 
    <h1>Menu Test</h1> 
    <ul id=”menu”> 
      <li class=”menu”><a href=”#”>Home</a></li> 
      <li class=”menu”><a href=”#”>Products</a>
         <ul>
            <li><a href=”#”>Sub-item 1</a></li> 
            <li><a href=”#”>Sub-item 2</a></li> 
            <li><a href=”#”>Item 3</a></li>
         </ul></li>
       <li class=”menu”><a href=”#”>Support</a> 
           <ul>
              <li><a href=”#”>Sub-item 1</a></li>
              <li><a href=”#”>Sub-item 2</a></li> 
           </ul></li> 
       <li class=”menu”><a href=”#”>Employment</a>
            <ul> 
               <li><a href=”#”>Sub-item 1</a></li> 
               <li><a href=”#”>Sub-item 2</a></li>
            </ul></li>
               <li class=”menu”><a href=”#”>Contact Us</a>
            <ul>
               <li><a href=”#”>Sub-item 1</a></li>
               <li><a href=”#”>Sub-item 2</a></li> 
            </ul></li> 
    </ul> 
    </body>
    JavaScript
    Code:
    // global variables for timeout and for current menu 
    var t=false,current; 
    
    function SetupMenu() {
      if (!document.getElementsByTagName) return;
      items=document.getElementsByTagName(“li”); 
    
      for (i=0; i<items.length; i++) {
        if (items[i].className != “menu”) continue; 
        //set up event handlers 
        thelink=findChild(items[i],”A”); 
        thelink.onmouseover=ShowMenu; 
        thelink.onmouseout=StartTimer;
        //is there a submenu? 
        if (ul=findChild(items[i],”UL”)) {
          ul.style.display=”none”; 
          for (j=0; j<ul.childNodes.length; j++) {
             ul.childNodes[j].onmouseover=ResetTimer; 
             ul.childNodes[j].onmouseout=StartTimer;
          }
        }
      }
    } 
    
    // find the first child object of a particular type 
    function findChild(obj,tag) {
      cn = obj.childNodes; 
      for (k=0; k<cn.length; k++) {
        if (cn[k].nodeName==tag) return cn[k]; 
      }
      return false;
    }
    Last edited by samz; 09-21-2011 at 02:47 PM.

  • #2
    New Coder
    Join Date
    Sep 2011
    Location
    UK, South Wales, Newport
    Posts
    21
    Thanks
    8
    Thanked 0 Times in 0 Posts
    dont worry lol


  •  

    Posting Permissions

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