I am creating a dropdown that slides down when hovered over. This is some code that I had. I want to use HoverIntent to accomplish this goal.
.menu_img is the class on the image that is hovered over to start the slide down of the list
.page_nav is the class on the list that slides down when .menu_img is hovered over.
$(document).ready(function(){
$('img.menu_img').click(function () {
$('ul.page_nav').stop().slideDown('slow');
});
});
HTML
<div id="helper_bar">
<div class="page_width">
<img src="images/page_nav.png" alt="page_nav" title="use this to navigate the page" class="menu_img" width="179" height="33" />
</div>
</div>
<div class="page_width">
<ul class="page_nav">
<li><a href="#">About</a></li>
<li><a href="#">Services Offered</a></li>
<li><a href="#">The Team</a></li>
<li><a href="#">The Process</a></li>
</ul>
</div>
This is the code that I have. This works if you click on the img but if you switch .click to .hover it will hover out when you try to go to the li’s. This is why I brought in hoverIntent plugin but I’m not sure how to integrate it to get the proper solution I’m trying to create.
BTW i didn’t include the HTML code but its a simple image and ul li tags which I know are working fine. There is a display: none; on the ul li and I did some stuff to make it funciton properly in my layout. (i have the layout a bit different than a regular dropdown.) Either way, I’m very certain my CSS is right, I just need to figure out how to write the Jquery. Thanks!
[Updated Answer]
What you want to do is going to be a bit challenging with a hover effect. Here is a possible solution, but you can’t use
hoverIntentwith it because it needs the events to bubble, andmouseenterandmouseleaveevents don’t bubble. However, I have incorporated a hoverIntent-like effect in this solution. First wrap both items in a single div with the id ofmenu:And use this JS (inside a document.ready event):
Please ask if you have questions or problems with this solution.
[Original Answer]
hoverwill never work for what you want, since theullist can never be a child of animg. Every time you move off theimgthe menu will hide. What I would recommend, is something like this (Actually, I would recommend you use image replacement instead of an image, but lets just do one thing at a time):HTML
JS
This way the
mouseenterevent (or a delayed version of it with hoverIntent) fires when theliis hovered, and won’t fire again until the entire list is exited by the mouse. So, as long as the mouse is over thelior any of its children, themouseoutevent will never fire, allowing thepage_navto do its job as a menu.