Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bind mouseleave slideDown - only animates once

Status
Not open for further replies.

markjson

Programmer
Nov 10, 2010
9
GB
Hi,

I am trying to develop a top menu with a dropdown submenu, triggered slideDown upon hovering over #topmenu li; and triggered slideUp upon mouseleave #topmenu li as well as .about us.

I need to have ul.submenu separate as opposed to nested into ul#topmenu due to z-index issues.

Here is the HTML:

HTML:
        <ul id="topmenu">
        	<li id="aboutus"><a id="test" href="/about-us">about us</a>
            </li>
        </ul><!-- topmenu -->

       	<ul class="submenu aboutus">
           	<li><a href="/vision">vision</a></li>
           	<li><a href="/testimonials">testimonial</a></li>
	</ul>

And here is the jQuery:

Code:
	// Dropdown menu behaviour
	$("#topmenu li").hover(function(){
		var curclass='.' + $(this).attr('id');
		$(curclass).slideDown();
	}, function(){
		var curclass='.' + $(this).attr('id');
		$(this).add(curclass).bind('mouseleave',function(){
				$(curclass).slideUp();
		});
	});

Now, this works perfectly the first time I hover over it.

However, the next time I hover over #topmenu li, as soon as the mouseleaves #topmenu li, .submenu slides up.

The strange thing is that it works perfectly the first time, but fails the second time and thereafter.

Is there an issue with bind? or mouseleave?

Thanks in advance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top