为什么当我快速移动鼠标时,我的jQuery会崩溃

Why is my jQuery breaking when I move my mouse really fast?

本文关键字:我的 jQuery 崩溃 鼠标 移动 为什么      更新时间:2024-04-22

我做了一些悬停状态,在悬停元素时显示div。它的工作非常好,尽管如果我在它上面快速移动几次鼠标,它似乎会断开,并且div在刷新页面之前不再显示。

任何可能导致这种情况的想法都让我感到困惑。

$('#s2_coffeetable').hover(function() {
    $('#popup1').stop().animate({
        opacity: 'toggle'
    }, 5)
}, function() {
    $('#popup1').stop().animate({
        opacity: 'toggle'
    }, 5)
});
$('#s2_drinks').hover(function() {
    $('#popup2').stop().animate({
        opacity: 'toggle'
    }, 100)
}, function() {
    $('#popup2').stop().animate({
        opacity: 'toggle'
    }, 100)
});

尝试此.stop( [clearQueue] [, jumpToEnd] )jQuery引用。。。

.stop(true, true)

将这两个参数传递给停止功能。