2

它有点像这样:

$("example").hover(function(){
        ("example").stop().show(/*More Code*/, callback());
    }, function(){
        ("example").stop().hide(/*More Code*/, callback());
    }
)

因此,如果鼠标在第一个动画完成之前离开该区域,它将停止所有动画,并跳过回调。有没有办法使用 stop() 并仍然执行回调函数?

4

1 回答 1

1

使用setTimeout在动画结束时定时触发的 a 而不是回调。

$("example").hover(function(){
        $("example").stop().show(1000);
        setTimeout(function() { /* do something */ }, 1000);
    }, function(){
        $("example").stop().hide(1000);
        setTimeout(function() { /* do something */ }, 1000);
    }
);

另一种选择是使用.stop(true,true)而不仅仅是.stop().

这会清除队列,将动画发送到最后,并触发回调。

$("example").hover(function(){
        $("example").stop(true,true).show(1000);
    }, function(){
        $("example").stop(true,true).hide(1000);
    }
);
于 2011-01-27T04:09:06.917 回答