views:

810

answers:

1

Hi,

I am trying to make a menu that works like the one on this flash site:

http://elevensix.de/

When I click "portfolio", only then to the subnavigation links reveal themselves. Right now I have only managed to get a typical vertical "reveal subnavigation on hover menu" working.

What is required is that once the appropriate menu item it cicked, its submenu shows. This submenu remains revealed as the submenu items are hovered over then selected. When the submenu item is selected, the content shows, and both the menu and submenu remain visible (the selected menu and submenu item are given a distinct colour to show the navigation path). Whew.

Here is my html:

<div id="nav">
<ul>
    <li><a href="#">about</a></li>
    <li><a href="#">testimonials</a>
        <ul>
          <li><a href="#">testimonial1</a></li>
          <li><a href="#">testimonial2</a></li>
          <li><a href="#">testimonial3</a></li>
          <li><a href="#">testimonial4</a></li>
        </ul>
    </li> 
     <li><a href="#">Services</a>
        <ul>
           <li><a href="#">services1</a></li>
           <li><a href="#">services2</a></li>
           <li><a href="#">services3</a></li>
           <li><a href="#">services4</a></li>
       </ul>
    </li> 
    <li><a href="#">Gallery</a></li>
    <li><a href="#">Contact</a></li>
  </ul>

</div><!--end #nav-->

and here is my css:

  #nav {
  width:160px;
  position: relative;
  top: 250px;
  left: 20px;
  }

 #nav ul {
 margin:0px; 
 padding:0px; 
 }

#nav ul li {
line-height:24px; 
list-style:none; 
}

#nav a {
text-decoration: none;
color: #9d9fa2;
}

#nav ul li a:hover {
position:relative;
color: #00aeef;
}

#nav ul ul {
display:none; 
position:absolute; 
left:160px; 
top:4px; 
}

#nav ul li:hover ul {
display:block;
color: #00aeef;
}

#nav ul ul li { 
width:160px; 
float:left; 
display:inline; 
line-height:16px; 
}

.selected {
color: #00aeef !important;
}

Should I be giving the submenus a class so that I can hide then show them? And where would the class be applied? To the ul? could I use the same class for both submenus? Am I wrong in how I am applying the display:none values for this purpose?

Many thanks to all the clever people on here.

A: 

Do you want to show/hide submenu by click on item of main menu using JQuery? If it's so, you should include jquery.js file and write script, such as:

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
        var $j = jQuery.noConflict();
        $j(document).ready(function() {
        });
        function Reveal(a){
            var ul = a.parentNode.getElementsByTagName("UL").item(0);
            $j(ul).animate({height: 'toggle' ,opacity: 'toggle'}, "slow");
        }
</script>

Then you should call function Reveal on click link of menu:

<li><a href="#" onclick="Reveal(this);">testimonials</a>

You should exclude rule of unhidding from css for hovered li:

#nav ul li:hover ul {
/*display:block;*/
color: #00aeef;
}

And I recommend to use rule of outlining for links:

#nav ul a{outline:none;}

Now submenu will slowly appear and disappear by click on item of main menu. There are many functions for animating in JQuery. You can learn their here

greatromul
Wow - thank you so much for your fast response. That rule about outlining for links is great - thank you.I've been playing with your code and understand about 50% of what is going on - more study is in order.But I also figured out that I could use good'ole css and html - and only include the submenu html code on the pages where I wanted it to show since it doesn't have to be dynamic. Either way - so appreciate your help and will use code as launching pad for an improved navigation down the road.
heathwaller