Jump to content

show/hide div in nav menu


squigs

Recommended Posts

Hello, I am building a navigation bar with sub menus which appear when the main item is clicked and disappear when the user clicks elsewhere. I have read numerous posts concerning this topic but I'm not sure how to implement it. My code is as follows:

 

topNav.js

<script>
var timeout = 50;
var closetimer = 0;
var ddmenuitem = 0;

// open hidden layer
function mopen(id) {

// cancel close timer
 mcancelclosetime();

// get new layer and show it
 ddmenuitem = document.getElementById(id);
 ddmenuitem.style.visibility = 'visible';
}

// close showed layer
function mclose() {
if (ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime() { 
closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}
// need to somehow close layer when click-out
</script>

Html

<body>

    <div id="main_nav">

    <ul id="nav">

    <li class="nav"><a href="#" onclick="mopen('m1')">

    <span class="nav_parent">CONTACT US</span></a>

    <div id="m1">

 <a href="#">General Inquiries</a>  

 <a href="#">Request a Quote</a>

 <a href="#">Submit Plans</a>

 <a href="#">Submit Photos</a>

  </div></li>

            </ul>

        </div>

</body>

An example of this is at http://jsfiddle.net/schwiegler/t859A/21/

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.