2010-10-26 85 views
4

我不能爲我的生活弄清楚這段代碼的問題是什麼。動畫本身工作正常:.animate()中的匿名回調函數不起作用

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

} //end of if statement 

回答

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 
+0

*打在牆上的頭*非常感謝!我是昨天的新手 - 你能告訴我嗎? :P – 2010-10-26 15:41:45

+0

@hugh我們都去過那裏!如果此答案回答了您的問題,則可以通過單擊答案左側的空白記號來標記該答案。 – lonesomeday 2010-10-26 15:54:42

+0

你已經打勾;)謝謝隊友 – 2010-10-26 15:56:09

1

檢查API,你似乎沒有被調用函數右:

.animate(properties, [ duration ], [ easing ], [ callback ]) 

想這是你應該怎麼稱呼它:

.animate({"top": "+="+item_size}, speed, 'linear', function(){alert();}); 

linear更改爲您需要的任何緩動功能。

+0

謝謝你這麼多!我通過刪除{queue:false,duration:speed}並用速度替換它來解決了這兩個帖子前的問題,但我很高興知道如何在需要時包含此參數。 – 2010-10-26 15:42:39