Jquery 重复事件及如何避免

Jquery 重复事件及如何避免,jquery,javascript-events,mouseevent,delay,Jquery,Javascript Events,Mouseevent,Delay,我的jQuery代码是: $(document).ready(function () { $('.selector').mouseenter(function () { $(this).find('> ul').slideToggle('fast'); }); $('.selector').mouseleave(function () { $(this).find('> ul').slideToggle('fast');

我的jQuery代码是:

$(document).ready(function () {
    $('.selector').mouseenter(function () {
        $(this).find('> ul').slideToggle('fast');
    });
    $('.selector').mouseleave(function () {
        $(this).find('> ul').slideToggle('fast');
    });
});
工作地点:

我的代码是有效的,但如果你不小心,你可以快速攻击打开一个关闭面板。那么,是否存在延迟,或者更确切地说,有人可以做些什么来防止这种情况发生

$(document).ready(function () {
    $('.selector').mouseenter(function () {
        $(this).find('> ul').stop().slideToggle('fast');
    });
    $('.selector').mouseleave(function () {
        $(this).find('> ul').stop().slideToggle('fast');
    });
});

此外,可能去Bouncing插件对您也很有用


更新(使用反盎司):

此外,可能去Bouncing插件对您也很有用


更新(使用反盎司): 您可以尝试以下方法:

 $(document).ready(function () {
$('.selector').mouseenter(function () {
    $(this).find('> ul').hide().slideDown('fast');
});
$('.selector').mouseleave(function () {
    $(this).find('> ul').hide().slideUp('fast');
 });
});  
这把小提琴:

你可以试试这个:

 $(document).ready(function () {
$('.selector').mouseenter(function () {
    $(this).find('> ul').hide().slideDown('fast');
});
$('.selector').mouseleave(function () {
    $(this).find('> ul').hide().slideUp('fast');
 });
});  

这把小提琴:

谢谢你,很有魅力。还有,我将如何使用debounce?我正在研究它。请看一下更新的答案-我添加了另一个例子谢谢,工作得很有魅力。还有,我将如何使用debounce?我正在研究atm。请看一下更新的答案——我又增加了一个例子