Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Javascript Dropdown Menu

Options
  • 13-05-2004 11:33am
    #1
    Closed Accounts Posts: 2,313 ✭✭✭


    Could anyone help me make this dropdown menu dissappear when I move the mouse away from it? Its a free javacsript and I rekon its pretty simple but I dont know the commands and Ive only notepad to edit (so no handy F1 help on methods etc). The code is below.
    function InitMenu()
    {
    var bar = menuBar.children

    for(var i=0;i < bar.length;i++)
    {
    var menu=eval(bar.menu)
    menu.style.visibility = "hidden"
    bar.onmouseover = new Function("ShowMenu("+bar.id+")")
    var Items = menu.children
    for(var j=0; j<Items.length; j++)
    {
    var menuItem = eval(Items[j].id)

    if(menuItem.menu != null)
    {
    menuItem.innerHTML += "<Span Id="+menuItem.id+"_Arrow class='Arrow'>4</Span>"
    //var tmp = eval(menuItem.id+"_Arrow")
    // tmp.style.pixelLeft = menu.getBoundingClientRect().Right //- tmp.offsetWidth - 15
    FindSubMenu(menuItem.menu)}

    if(menuItem.cmd != null)
    {
    menuItem.onclick = new Function("Do("+menuItem.id+")") }

    menuItem.onmouseover = new Function("highlight("+Items[j].id+")")

    }

    }
    }
    function FindSubMenu(subMenu)
    {
    var menu=eval(subMenu)
    var Items = menu.children
    for(var j=0; j<Items.length; j++)
    {
    menu.style.visibility = "hidden"
    var menuItem = eval(Items[j].id)


    if(menuItem.menu!= null)
    {
    menuItem.innerHTML += "<Span Id="+menuItem.id+"_Arrow class='Arrow'>4</Span>"
    // var tmp = eval(menuItem.id+"_Arrow")
    //tmp.style.pixelLeft = 35 //menuItem.getBoundingClientRect().right - tmp.offsetWidth - 15
    FindSubMenu(menuItem.menu)
    }

    if(menuItem.cmd != null)
    {
    menuItem.onclick = new Function("Do("+menuItem.id+")") }

    menuItem.onmouseover = new Function("highlight("+Items[j].id+")")

    }
    }
    function ShowMenu(obj)
    {
    HideMenu(menuBar)
    var menu = eval(obj.menu)
    var bar = eval(obj.id)
    bar.className="barOver"
    menu.style.visibility = "visible"
    menu.style.pixelTop = obj.getBoundingClientRect().top + obj.offsetHeight + Bdy.scrollTop
    menu.style.pixelLeft = obj.getBoundingClientRect().left + Bdy.scrollLeft
    }

    function highlight(obj)
    {
    var PElement = eval(obj.parentElement.id)
    if(PElement.hasChildNodes() == true)
    { var Elements = PElement.children
    for(var i=0;i<Elements.length;i++)
    {
    TE = eval(Elements.id)
    TE.className = "menuItem"
    }
    }
    obj.className="ItemMouseOver"
    window.defaultStatus = obj.title
    ShowSubMenu(obj)
    }

    function Do(obj)
    {
    var cmd = eval(obj).cmd
    window.navigate(cmd)

    }

    function HideMenu(obj)
    {
    if(obj.hasChildNodes()==true)
    {
    var child = obj.children

    for(var j =0;j<child.length;j++)
    {
    if (child[j].className=="barOver")
    {var bar = eval(child[j].id)
    bar.className="Bar"}

    if(child[j].menu != null)
    {
    var childMenu = eval(child[j].menu)
    if(childMenu.hasChildNodes()==true)
    HideMenu(childMenu)

    childMenu.style.visibility = "hidden"
    }
    }

    }
    }
    function ShowSubMenu(obj)
    {
    PMenu = eval(obj.parentElement.id)
    HideMenu(PMenu)
    if(obj.menu != null)
    {
    var menu = eval(obj.menu)
    menu.style.visibility = "visible"
    menu.style.pixelTop = obj.getBoundingClientRect().top + Bdy.scrollTop
    menu.style.pixelLeft = obj.getBoundingClientRect().right + Bdy.scrollLeft
    if(menu.getBoundingClientRect().right > window.screen.availWidth )
    menu.style.pixelLeft = obj.getBoundingClientRect().left - menu.offsetWidth
    }
    }



Advertisement