jQuery:animate()函数完成后如何触发回调函数

jQuery:animate()函数完成后如何触发回调函数,jquery,Jquery,我希望能够在事件堆栈中使用回调,但不能在最后使用回调。我尝试过这样做,但在调用回调后,代码似乎逃过了任何影响 $(this).animate({//animate image top:0 }, aniTime) .delay(1000, function(){ //some code }) .animate({//animate ima

我希望能够在事件堆栈中使用回调,但不能在最后使用回调。我尝试过这样做,但在调用回调后,代码似乎逃过了任何影响

$(this).animate({//animate image
                top:0
            }, aniTime)

            .delay(1000, function(){

             //some code

            })

            .animate({//animate image
                top:250
            }, aniTime)

有没有办法做到这一点,或者这是不可能的/最佳做法?

您可以通过使用animate的
complete
回调参数来实现这一效果。这将在延迟时间开始的同时,在完成第一个动画时运行其内容

例如:

$(this).animate({//animate image
        top:0
    }, aniTime,
    // complete callback follows:
    function(){
        $('otherElement').fadeOut(200);
    })
    .delay(1000)
    .animate({//animate image
        top:250
    }, aniTime)

我不理解这个问题,所以您想将top设置为0,等待1000毫秒,然后将top设置为250?在下一个动画之前会有一个延迟,但希望在回调中淡出其他一些选择器。这有道理吗?我知道我可以在范围之外做,但我想知道是否有可能保持代码整洁,所以你想在延迟后淡出另一个元素?jQuery
delay()
不接受回调作为参数。是 啊因此,它与最终动画同时执行