2013-08-04 65 views
-1

我這行延遲彈出20秒的setTimeout

的$(document)。在( '準備好',contentLockerShow);

該生產線將彈出一個名爲contentLockerWrapper的div在頁面加載時,我只是想拖延彈出20秒,所以我改變了

的$(document)。在('準備',contentLockerShow);

的setTimeout(contentLockerShow,20000);

但是contentLockerBackground彈出窗口在包裝和屏幕被鎖定之前彈出apears。

這是功能

function contentLockerShow(){ 
     contentLockerBackground.animate({'opacity':'.6'}, 500); 
     contentLockerWrapper.fadeIn(500);  
     if(contentLockerCompleted == false){ 
      contentLockerCompleted = true; 
      console.log(contentLockerCompleted);  
     } 
+0

希望你會發現這個鏈接有用 http://stackoverflow.com/questions/3468607/why-does-settimeout-break-for-large-millisecond-delay-values –

回答

0

最初我誤解你的問題。在jQuery中,您可以告訴動畫在另一個動畫完成之前不要啓動。現在,您可以在同一時間獲得背景和包裝,都需要花費半秒的時間加載。試試這個:

function contentLockerShow(){ 
     contentLockerWrapper.fadeIn(500, function() 
      contentLockerBackground.animate({'opacity':'.6'}, 500); 
     );  
     if(contentLockerCompleted == false){ 
      contentLockerCompleted = true; 
      console.log(contentLockerCompleted);  
     } 

同樣,如果你想在窗口等待鎖定,直到後臺加載完成後,可以進一步修改它是這樣的:

function contentLockerShow(){ 
     contentLockerWrapper.fadeIn(500, function() 
      contentLockerBackground.animate({'opacity':'.6'}, 500, function() 
       if(contentLockerCompleted == false){ 
         contentLockerCompleted = true; 
         console.log(contentLockerCompleted);  
       } 
      ); 
     );