.animate()中的匿名回调函数无法正常工作

hug*_*son 4 jquery jquery-callback jquery-animate

我不能为我的生活弄清楚这段代码的问题是什么.动画本身很好用:

if (!list.is(':animated')) {
    list.animate(
        {"top": "+="+item_size},
        {queue:false, duration:speed},
        function() {
            alert();
        }
    ); // end of animate function

} //end of if statement
Run Code Online (Sandbox Code Playgroud)

lon*_*day 5

你混淆了两个签名.animate().您需要将回调作为options参数的一部分:

if(!list.is(':animated')){
    list.animate({
        top: "+="+item_size
    }, //end of properties argument
    {
        queue: false, 
        duration: speed,
        complete: function(){
            alert();
        } //end of callback
    }  // end of options argument
    ); // end of animate function
} //end of if statement
Run Code Online (Sandbox Code Playgroud)