views:

266

answers:

2

Hey Guys,

i have a Menu with the following Code:

    <div id="head_navigation">
     <ul>
         <li><a href="javascript:void(0);"><img src="img/start.jpg" width="57" height="40" title="start" alt="" /></a></li>
         <li><a href="javascript:void(0);"><img src="img/favoriten.jpg" width="87" height="40" title="favoriten" alt="" /></a></li>
        </ul>
    </div>

    <div id="head_subnavigation">
     <ul id="start" class="hidden">
         <li><div class="button"><a href="javascript:void(0)" onclick="cwload('arztauswertung.html','start');" title="Rezeptsuche"><img src="img/icons/icon_rezeptsuche_on.png" width="50" height="62" alt="Rezeptsuche" /><br />Rezeptsuche</a></div></li>
         <li><div class="button"><a href="javascript:void(0)" onclick="cwload('arztauswertung.html','start');"><img src="img/icons/icon_zuzahlung_on.png" width="50" height="62" alt="Zuzahlung" /><br />Zuzahlung</a></div></li>
         <li><div class="button"><a href="javascript:void(0)" onclick="cwload('arztauswertung.html','start');"><img src="img/icons/icon_abrechnung_on.png" width="50" height="62" alt="Abrechnung" /><br />Abrechnung</a></div></li>
        </ul>
    </div>

'#head_subnavigation' has the CSS "display:none". When i hover Image with Title "start", then the < ul > with ID "start" is shown. And so on.

It works fine, but my Problem is "Mouseout". When i use Mouseout Event for the '#head_navigation', then my subnavigation dissapears when i want to hover the li items on the submenu. You understand what i mean???

How can i use Mouseout only when i jump to another li Item in the "head_navigation" div or on Mouseout the '#head_subnavigation' div, BUT NOT when i move with the mouse from 'head_navigation' to 'head_subnavigation' ??? Can anyone help? Have tried a lot of things - nothing really works... :(

Thanks for that.

Greetings, Sascha

CLARIFICATION

I have a nested navigation menu where the sub-navigation is displayed onmouseover of the image $('#head_navigation img') based on the title attribute.

I would like the sub-navigation to remain open until I mouse out of either the sub navigation or the image.

A: 

You could do this:

$('#head_navigation li a').hover(function(){

    // Hide the visible subnavigations
    $('#head_subnavigation ul:visible').css('display','none');

    // Show the appropriate subnavigation
    $('#head_subnavigation ul#' + $(this).attr('title')).css('display','block');

});

That way the currently visible #head_subnavigation ul's are hidden when you mouse over a new top level navigation li. You should wrap the whole navigation in a div to handle the mouseout event when a user leaves the menu area completely.

$('#navigationDiv').mouseout(function(){

    $('#head_subnavigation ul:visible').css('display','none');

});

The problem with having a wrapping div is that if the menu extends beyond the div, the mouseout event will fire thus hiding your menu. There is another approach you could take...

// Globals
var menuHoverTimer = 0;
var menuHoverTimerLimit = 3; // 3 seconds
var menuHoverTimerIntervalID;

function stopHoverTimer(){
    clearInterval(menuHoverTimerIntervalID);
}
function resumeHoverTimer(){
    // This will run the menuHoverHandler function every 1 second
    menuHoverTimerIntervalID = setInterval(menuHoverHandler, 1000);
}
function menuHoverHandler(){
    menuHoverTimer++;
    if(menuHoverTimer > menuHoverTimerLimit) {
        stopHoverTimer();
        $('#head_subnavigation ul:visible').css('display','none');
        menuHoverTimer = 0;
    }
}

Then in each of your hover actions, on mouse over run stopHoverTimer() and on mouse out run resumeHoverTimer(); The way I have that setup, it will hide the menus after 3 seconds of the user not mousing over the menu. I think you may want that to be shorter.

a432511
perfekt @a432511 - the Timer Solutions works absolutely perfect for me!!!! Thanks so much!
codeworxx
glad I could help!
a432511
globals are grim, should not be advising to use them.
redsquare
do you have a better solution?
a432511
A: 

The quickest way is to wrap all your menu into a bigger DIV and hide the menu on the mouseout event of that DIV. You should also make sure that only one submenu is visible at any given time (eg. hiding the open menu when showing a new one).

Patonza