function dropMenu(obj) { $(obj).each(function () { var theSpan = $(this); var theMenu = theSpan.find(".submenu"); var tarHeight = theMenu.height(); theMenu.css({ height: 0, opacity: 0 }); var t1; function expand() { clearTimeout(t1); theMenu.stop().show().animate({ height: tarHeight, opacity: 0.7 }, 200); } function collapse() { clearTimeout(t1); t1 = setTimeout(function () { theMenu.stop().animate({ height: 0, opacity: 0 }, 200, function () { $(this).css({ display: "none" }); }); }, 250); } theSpan.hover(expand, collapse); theMenu.hover(expand, collapse); }); } $(document).ready(function () { dropMenu(".drop_menu"); });