如果在 jQuery 中动画停止,如何防止回调?

Cha*_*haa 1 jquery animation hover hoverintent

我正在开发一个包含很多可悬停 div 的项目。我写了一个动画来做到这一点:

鼠标悬停时,图像淡出,作为回调,包含信息的 div 淡入。然后,鼠标移出时,信息 div 淡出,作为回调,图像淡入。我正在使用悬停意图插件。

我的问题是,如果你在 div 上停留足够长的时间,一切都会正常。但是如果你在上面停留 300 毫秒,动画就会停止,但显示信息 div 的回调仍然会被调用,忽略鼠标移出事件。这会导致 info div 永久保留......

这是我的代码:

 var infoPaneSettings = {
    sensitivity: 3,
    interval: 200,
    timeout: 500,
    over: showPane,
    out: hidePane

    }   

function showPane() {
    var entry = $(this);
    $('.featured_img', entry).fadeTo(1000, 0, 
        function(){
        $('.infoPane', entry).fadeTo(200, 1);
        });


}

function hidePane() {
    var entry = $(this);
    $('.infoPane', entry).fadeTo(300, 0, 
        function(){
        $('.featured_img', entry).fadeTo(200, 1);
        });
}

$('.entry').each(function(){
    $(this).hoverIntent(infoPaneSettings);
});
Run Code Online (Sandbox Code Playgroud)

我希望你可以帮助我 !

Ari*_*iel 5

在开始新动画之前,在元素上使用http://api.jquery.com/stop/ 。它将阻止运行回调。

  • 谢谢,我正在写“.stop(true, true)”,它应该是“.stop(true, false)”。现在可以正常使用了,再次感谢! (2认同)