Solved

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

Posted on 2014-10-31
7
393 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 57

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 57

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Mark
ID: 40415840
progressively
0
 
LVL 57

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 57

Expert Comment

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

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

734 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