$(document).ready(function () {
$('.selector').mouseenter(function () {
$(this).find('> ul').stop().slideToggle('fast');
});
$('.selector').mouseleave(function () {
$(this).find('> ul').stop().slideToggle('fast');
});
});
http://jsfiddle.net/Au7LA/3
也可能去抖插件对你有用http://benalman.com/code/projects/jquery-throttle-debounce/docs/files/jquery-ba-throttle-debounce-js.html
更新(使用去抖动):
$(document).ready(function () {
var toggle = function (show) {
return function () {
var $el = $(this);
var isHovered = $el.is(':hover');
var animation = show && isHovered ? 'slideDown' : 'slideUp';
$el.children('ul').stop()[animation]('fast');
};
}
var mouseenter = $.debounce(400, toggle(true));
var mouseleave = toggle(false);
$('.selector')
.on('mouseenter', mouseenter)
.on('mouseleave', mouseleave);
});
http://jsfiddle.net/vpetrychuk/4C6CV/