jQuery Drop down menu without setTimeout
I worked a lot with drop-down menus like most of you. There are many stable versions of DD menus using pure javascript & CSS or only CSS with cross-browser support and you’ll get them free from many menu maker websites or desktop applications. So I’m not going to reinvent the wheel.
I’m a freaking fan of jQuery and always use it for drop-down menus with my custom jQuery code. It’s a must to use a delay for javascript driven dd menus even for jQuery when you want to give it some effect like slideDown or slideUp (For CSS dropdown menus it’s not possible & thus no need to use delay). I always wished to use jQuery without any setTimeout function for the drop-down menus. And I did it which I’m gonna share with you.
$(function () {
$("ul>li").hover(function () {
$(this).find("ul.sub").slideDown('fast');
$(this).addClass("hover");
$(this).hover(
function () {},
function () {
$(this).find("ul.sub").slideUp('fast');
});
},
function () {
$(this).removeClass("hover");
})
})
The main tricky part is using hover inside hover function:
$(this).hover(
function () {},
function () {
$(this).find("ul.sub").slideUp('fast');
});
This removes the mouseover function (first function of hover) when mouse hover into the li so the slideDown does not happen again when the mouse enter into the inner ul/li. Hope that makes sense. You may like to add a delay and do some more fine tunes.
Happy Coding!
Related posts:
- IE6 fix for select box over absolute positioned element
- Gmail uploader clone with drag drop feature : Free Download with source code
- jQuery Mix Photo Gallery
- A better process to find maximum z-index within a page
- jQuery vs. prototype.js
2 Comments to “jQuery Drop down menu without setTimeout”
Leave a Reply



My Elance Profile
This is really so tricky! great job! @rahen
great, i like it
thank’s