/* * * credits to http://css-tricks.com/long-dropdowns-solution/ * */ var maxheight = 400; $(function(){ $(".dropdown > li").hover(function() { var $container = $(this), $list = $container.find("ul"), $anchor = $container.find("a"), height = $list.height() * 1.1, // make sure there is enough room at the bottom multiplier = height / maxheight; // needs to move faster if list is taller // need to save height here so it can revert on mouseout $container.data("origheight", $container.height()); // so it can retain it's rollover color all the while the dropdown is open $anchor.addclass("hover"); // make sure dropdown appears directly below parent list item $list .show() .css({ paddingtop: $container.data("origheight") }); // don't do any animation if list shorter than max if (multiplier > 1) { $container .css({ height: maxheight, overflow: "hidden" }) .mousemove(function(e) { var offset = $container.offset(); var relativey = ((e.pagey - offset.top) * multiplier) - ($container.data("origheight") * multiplier); if (relativey > $container.data("origheight")) { $list.css("top", -relativey + $container.data("origheight")); }; }); } }, function() { var $el = $(this); // put things back to normal $el .height($(this).data("origheight")) .find("ul") .css({ top: 0 }) .hide() .end() .find("a") .removeclass("hover"); }); });