Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-10-31
7
Medium Priority
?
459 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 60

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 60

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Mark
ID: 40415840
progressively
0
 
LVL 60

Accepted Solution

by:
Julian Hansen earned 2000 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 60

Expert Comment

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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

886 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