2011-11-22 168 views
1

有人可以告訴我爲什麼我的功能沒有執行後,我的圖像顯示?jquery延遲不起作用

$("#screen").css("background-image", "url('screens/animated/077.gif')").delay(5000).queue(function() { 
     $("#screen").css("background-image", "url('screens/animated/078.gif')").delay(5000).queue(function() { 
      buttonClick(16); 
     }); 

    });   

不知道爲什麼它不會調用我的buttonClick(16);功能。

+1

是否定義了?你的控制檯有任何錯誤嗎? – Tadeck

+0

你有沒有嘗試過一些簡單的調試,比如在延遲函數之外調用buttonClick? –

回答

0

因爲你沒有出隊。

$("#screen").css("background-image", "url('screens/animated/077.gif')").delay(5000).queue(function() { 
    $(this).css("background-image", "url('screens/animated/078.gif')").delay(5000).queue(function() { 
     $(this).dequeue(); 
     buttonClick(16); 
    }).dequeue(); 
}); 
+1

好!謝啦! –

0

隊列函數接收一個參數,你應該在下一個函數運行時調用它。 例如:

$().queue(function (next) { 
    // Do what you need 
    next(); 
}); 
1

您可以只是動畫而不是花花公子? animate()可以傳遞時間並且還具有回調函數,因此一旦第一個動畫完成,您可以運行更多代碼,即

$(this).animate(function(){ 
    //Do animation 
},1000,function(){ 
    //Animation is complete, do something else like the next animation 
    $(this).animate(function(){ 
     //Another animation to run once the first is complete 
    }); 
});