views:

62

answers:

2

How do I modify this script so that when I mouseout of the submenu, it still remains open for x seconds?

Currently it slidesup (hides) as soon as I mouseout. I need hoverintent like functionality where it hides after x seconds.

HTML:

<div id="navigation">
        <ol>
            <li><a href="#" class="parent">Menu 1</a>
                <div class="submenu clear"><div class="listings clear"> content</div></div>
            </li>         
        </ol>
</div>

Thanks for your help!

A: 

I feel like I'm doing someone elses work here, but anyway, the code that makes the thing go away seems like it's this:

bm_item_content_obj.slideUp( 'fast',  function() {
    bm_item_link_obj.removeClass("bm-item-link-hover");
});

So just wrap it in a timer if you want it to happen after x seconds:

setTimer(function() {

    bm_item_content_obj.slideUp( 'fast',  function() {
        bm_item_link_obj.removeClass("bm-item-link-hover");
    });

}, 5000); // 5 seconds
Luca Matteis
The menu stays open until clicked outside. Hm...
Nimbuz
+2  A: 

Something like:

jQuery(element_here).delay(5000).slideup('fast', function() {
    bm_item_link_obj.removeClass("bm-item-link-hover");
});

would work

If your basing it on your html in your question/ JSfiddle, you would change your JS in the select statement to look like this:

case "slideUp":
    bm_item_content_obj.delay(5000).slideUp( 'fast',  function() {
        bm_item_link_obj.removeClass("bm-item-link-hover");
    });

Also it would be better to wrap:

$("#navigation ol").bigmenu();

in:

$(document).ready(function () {

    // NAVIGATION
    $("#navigation ol").bigmenu();

});

than

$(window).load(function () {

    // NAVIGATION
    $("#navigation ol").bigmenu();

});

To get other links to slide up when you go on to another link straight away you need this:

$(".submenu").not(bm_item_content_obj).stop(true, true).slideUp("fast");

below whats already in:

 case "slideDown":

So it will look like:

case "slideDown":
      bm_item_content_obj.height("auto");
      bm_item_content_obj.slideDown(100);

      $(".submenu").not(bm_item_content_obj).stop(true, true).slideUp("fast");
break;
Correct answer - tick it.
LiverpoolsNumber9
Almost perfect, just one thing: when I move from one menu to the other, both the submenus remain open; the previous one should be closed.
Nimbuz
There must be some error in your code then. If you provided a working example on jsFiddle instead of just the code that might help.
I copied the html into jsFiddle and it works. The delay is set to 5 seconds (5000 milliseconds). Maybe you need to change that.
Yes, it works but the thing is, say if you open submenu of 'parent1' and move to 'parent2' the previously opened subemnu(s) should close immediately, that doesn't happen.
Nimbuz
But you said you wanted a delay to happen. It You want it to close straight away you don't need the delay part.
1) I mouseover a menu and the submenu opens. 2) I move out for a sec but the submenu doesn't close because there's delay for closing, nice. 3) Now when I mouseover menu1, submenu opens, then I quickly mouseover menu2 and its submenu also opens, THEN, the submenu previously opened of menu1 should close immediately. That is, as soon as the newer submenu opens, all previous 'open' submenus should close.
Nimbuz
I get what you mean now. Updated my answer, which I tested in jsFiddle and works fine.
Awesome, thanks!
Nimbuz
Your welcome :)