jQuery:animate complete()事件在停止()时执行

jQuery:animate complete()事件在停止()时执行,jquery,event-handling,jquery-animate,Jquery,Event Handling,Jquery Animate,假设我有这个 $(".a").animate( {"left":"100%"}, {duration:50000, complete:function(){ $(".a").css("background-color","black"); }} ); $(".b").mouseover(function(){ $(".a").stop(); }); 当.b处于鼠标上方-ed时,.a将停止(),因此其完成

假设我有这个

$(".a").animate(
        {"left":"100%"},
        {duration:50000, complete:function(){
             $(".a").css("background-color","black");
        }}
);

$(".b").mouseover(function(){
        $(".a").stop();
});
.b
处于
鼠标上方
-ed时,
.a
停止()
,因此其
完成:事件不会被触发

即使它停止其
complete:event
将被触发,我该怎么做?

还有比这更好的解决办法吗

function aaa(){
   $(".a").css("background-color","black");
 }    

$(".a").animate(
        {"left":"100%"},
        {duration:50000, complete:function(){
            aaa();
        }}
);

$(".b").mouseover(function(){
        $(".a").stop();
        aaa();
});

[更新] 这就是我的代码实际上的样子,很抱歉之前没有显示它

$(".a").animate(
        {"left":"100%"},
        {duration:50000, complete:function(){
             alert("A");
        }}
);

$(".b").mouseover(function(){
        $(".a").stop().animate(
             {"top":"100%"}
        )
});
我希望只执行一次
警报(“A”)
。。但是我不会阻止用户在
鼠标上方
-ing
.b
停止
.a

如果我这样写
.b
鼠标:

$(".b").mouseover(function(){
        $(".a").stop().animate(
             {"top":"100%"}
             {complete:function(){
                  alert("A");
             }}            
        )
});

它可能会发出两次警报(“A”)
,我不希望……

为什么需要触发它,难道你不能在
.stop()
调用后立即调用绑定到
complete:event
的同一个函数,并获得相同的效果吗?

你正在查找的
'jumpToEnd'
参数:

这将实现以下目的:

$(".a").stop(true,true);

出于某种原因,我只看了你一半的问题,而你已经提出了这个建议。不知道我怎么会错过。对不起,谢谢你的建议!我已经更新了这个问题。。而stop'jumpToEnd'参数就是我要找的。问题解决:谢谢!!这就是我一直在寻找的。我应该在jQueryAPI中阅读更多内容。。