Solved

How to prevent jquery dropdown menu from closing when mouse moves out of layer

Posted on 2014-10-31
7
341 Views
Last Modified: 2014-10-31
    <!-- BEGINNING OF MENU -->  

		<!--<ul class="dropdown" style="z-index:1;margin-left:15px !important;">-->
		<ul class="dropdown" style="z-index:1;margin-left:10px !important;">
        	<li>	
 	             <table border=0><tr><td><img 

Open in new window


I have a complicated navigation menu with more then 3 steps (menu->submenu->subsubmenu), I want to make it so any menu or submenu opens on mouseover or click (as it does now) but does not close if the mouse goes out outside the range of the menu/submenu...

How can I achieve this..

Thanks
0
Comment
Question by:Mark
  • 4
  • 3
7 Comments
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 40415781
What would be the mechanism for hiding the menu again?
0
 

Author Comment

by:Mark
ID: 40415790
If the mouse leaves the menu boundary, the menu/submenu/... should remain open for half a second giving the user a chance to move their mouse back onto the menu incase they accidentally moved their mouse outside the boundary while trying to navigate the menu
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 40415832
Then you have to bind to the mouseover event for the <li> and set a class on the li to show the menu and submenu.

At the same time you need to start a timer (setTimeout) which if it fires hides the menu - on the mouseover event you would then clear the timer to prevent it firing.

The question is do you want this behaviour to be only on the sub-sub menu - or the sub menu or progressively i.e. if over main menu - that becomes sticky - then if go over sub-sub menu both become sticky?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Mark
ID: 40415840
progressively
0
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 40415863
Then you would need something like the code below. Guessing here because don't have your code - you would need to create (replace) the .open class and style it to show your menu items.
(untested - so you might need to tweak)
$(function() {
   var handleTimeout = null; // HANDLE TO HOLD TIMEOUT
   var TIMEOUT=300;   // TIMEOUT LENGTH

   // INTERCEPT MOUSEOVER ON <li> ELEMENTS
   $('ul.dropdown li').mouseover(function() {
      // CLEAR THE TIMEOUT IF IT EXISTS
      if (handleTimeout != null) clearTimeout(handleTimeout);
      // ADD A CLASS TO THE MENU ITEM TO OPEN IT
      $(this).addClass('open'); // Change class as needed and style
 
      // SET A TIMEOUT TO HIDE MENU AFTER TIMEOUTms
      handleTimeout = setTimeout(function() {
         $('li.open').removeClass('open');
         handleTimeout = null;
      }, TIMEOUT);
  });
});

Open in new window

0
 

Author Closing Comment

by:Mark
ID: 40415873
Thanks!
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 40415899
You are welcome - good luck with it.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now