2013-08-04 61 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);  
       } 
      ); 
     );