Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

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

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 59

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
How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

 

Author Comment

by:Mark
ID: 40415840
progressively
0
 
LVL 59

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 59

Expert Comment

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Suggested Courses

721 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