Skip to content

Instantly share code, notes, and snippets.

@terkel
Created May 18, 2011 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terkel/978291 to your computer and use it in GitHub Desktop.
Save terkel/978291 to your computer and use it in GitHub Desktop.
jQuery Dropdown plugin
// jQuery Dropdown plugin
(function ($) {
$.fn.dropdown = function (options) {
var opts = $.extend({
child: 'ul:first',
hoverClass: 'hover',
showTimeout: 100,
showSpeed: 200,
hideTimeout: 200,
hideSpeed: 100
}, options);
return this.each(function () {
var $this = $(this),
$child = $this.find(opts.child);
$this.hover(function () {
$.data($child, 'cancelHide', true);
setTimeout(function () {
if ($.data($child, 'cancelHide')) {
$this.addClass(opts.hoverClass);
$child.slideDown(opts.showSpeed);
}
}, opts.showTimeout);
}, function () {
$.data($child, 'cancelHide', false);
setTimeout(function () {
if (!$.data($child, 'cancelHide')) {
$child.slideUp(opts.hideSpeed, function () {
$this.removeClass(opts.hoverClass);
});
}
}, opts.hideTimeout);
});
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment