0
<ul id="mainNav">
  <li> <a href="#" class="greenTheme">MainNav</a>
    <ul class="subNav gTheme">
      <li class="first"><a href="#">SubNav1</a><span></span></li>
      <li><a href="#">SubNav2</a><span></span></li>
    </ul>
  </li>
</ul>

I am developing a dropdown menu with jQuery hover function. I need to put delay on the hide function. I am using the following piece of code.

//Show/Hide
$('#mainNav > li').each(function(e){
$(this).hover(function(){
    $(this).find('ul.subNav').show();
}, function(){
    $(this).find('ul.subNav').delay(100000).hide();     
    });
});

I used the delay function here but it is not working as expected. Please help. Thanks in advance.

1
  • 1
    I'll be the first to mention hoverIntent. Commented Dec 20, 2011 at 15:08

3 Answers 3

1

You can add hide to the animation queue by adding a duration. As mentioned above without any duration it will not become a part of the queue or "stack". Check out this jsFiddle: http://jsfiddle.net/mkprogramming/hyEC5/#base

//Show/Hide
$('#mainNav > li').each(function(e){
  $(this).hover(function(){
    $(this).find('ul.subNav').show(); //fadeIn();
  }, function(){
    $(this).find('ul.subNav').delay(1000).hide(1);    //fadeOut();
  });
});

Since you're using jQuery i'd use fadeIn() and fadeOut for a much more professional effect.

Sign up to request clarification or add additional context in comments.

Comments

0

To add show or hide to the jQuery animation queue you have to use an animation duration (eg 1ms)

$(this).find('ul.subNav').delay(100000).hide(1);     

http://api.jquery.com/show/

When a duration is provided, .show() becomes an animation method. The .show() method animates the width, height, and opacity of the matched elements simultaneously.

Comments

0

Just a suggestion, you could use HoverIntent for that, it would be much better. Sample: http://www.thatsquality.com/articles/creating-delayed-drop-down-menus-in-jquery-without-losing-accessibility

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.