2012-01-09 84 views
0

我有以下一段代碼正在從點擊功能運行。由於某些原因,動畫降至100px的部分從不運行console.logmy_function(),它會跳過您放置在那裏的任何內容。動畫高達200px的部分都運行良好。是什麼賦予了?動畫後跳過jQuery功能

if($(this).hasClass('open')) 
{ 
    $(this).removeClass('open').addClass('closed'); 
    $(this).animate({'width': '100px'}, {queue:false, duration:150, easing: 'linear'}).delay(160, function(){ 
    //Nothing in here ever get run?? 
    console.log('closed'); 
    my_function(); 
    }); 
} 
else 
{ 
    $(this).removeClass('closed').addClass('open'); 
    $(this).animate({'width': '200px'}, {queue:false, duration:200, easing: 'linear'}).delay(210, function(){ 
    console.log('opened'); 
    my_function(); 
    }); 
} 

回答

5

$.fn.delay沒有回調參數。

http://api.jquery.com/delay/

+0

我也在想這個 - 但他說else語句有效。但我無法理清爲什麼這樣做會奏效。有什麼想法嗎? – mrtsherman 2012-01-09 16:05:36

+0

我不認爲這是可能的。 jsFiddle即將推出 – 2012-01-09 16:07:04

+1

這是一個小提琴。它確實觸發了一個console.log http://jsfiddle.net/Tentonaxe/tRUBr/ – 2012-01-09 16:09:42

1

您應該使用一個回調.animate,而不是試圖用.delay。試試這個:

$(this).animate({'width': '100px'}, 150, function(){ 
    console.log('closed'); 
    my_function(); 
}); 
+0

沒有這個快樂 – 2012-01-09 16:09:41

+0

對不起,我以前的例子有一個語法錯誤。用更簡單的解決方案編輯答案。 – bfavaretto 2012-01-09 16:16:21

+0

關閉時仍然沒有將任何內容記錄到控制檯:/ – 2012-01-09 16:21:07