0

これら2つの機能があるとしましょう:

$(".a").animate(
        {"left":"100%"},
        {duration:10000, complete:function(){
             //Something is triggered!! e.g 
             alert("a");
            //Please note: In actual case it is never as simple as alert("a").
        }}
);

$(".b").mouseover(function(){
    $(".a").stop().animate({"top":"100px"},{duration:5000});
});
  • これらによると、-ed である .a限り停止し、トリガーされます。.bmouseoveranimate({"top":"100px"},{duration:5000})

  • しかし、私はそれが-ed のときにalert("a") 一度してからトリガーしたいのです。.bmouseoveranimate({"top":"100px"},{duration:5000})

ただし、この方法で 2 番目の関数を設定することはできません。

$(".b").mouseover(function(){
        //something happens! e.g
        alert("a");
        $(".a").stop().animate({"top":"100px"},{duration:5000});
    });
  • done の後に -edの場合はalert("a") 2 回になります。.bmouseover.aanimate

を試しましたstop()jumpToEnd parameter、理想的ではありません

.bmouseover-ed になるたびに、 は即座に完了し、にシフトされ.aます。私はそれがどこにあるのか、まだ秒がトリガーされる前に欲しいanimte.aleft:100%stopalert("a")animate


誰かがこれに対する迅速かつ簡単な解決策を提供できれば、私は非常に感謝しています!

4

2 に答える 2

1
$(".a").animate(
        {"left":"100%"},
        {duration:10000, complete:myAfterWork} // Use the function name only
);

$(".b").mouseover(function(){
    myAfterWork();
    $(".a").stop().animate({"top":"100px"},{duration:5000});
});

function myAfterWork()
{
  if($(".a").is(":animated"))
  {
    //Access $(".a") here and do your job

    //Note if you use $(this) in place of $(".a") it will be different 
    //when called from .a's animation than from .b's animation
  }

}
于 2012-05-22T08:55:29.793 に答える
1

に対してフィルタリングすることで、要素が現在アニメーション化:animatedされているかどうかを確認できます。

$('.b').mouseover(function () {

    // if NOT animating, then terminate
    if (!$('.a').is(':animated')) { return; }

    // carry on

});
于 2012-05-22T08:53:40.903 に答える