2012-02-05 57 views
0

下面的代碼在我的網頁加載時啓動一個浮動div,但是我需要它在啓動前有一個60秒的延遲。誰能幫忙?你可以在www.bizassist.co.za上看到浮動div的演示。Float-In Div需要延遲

謝謝。

代碼:

var timer; 
var h = -450; 
var w = 500;  
var t = 150; 

function startAp() { 
    setLeft(); 
    showAp(); 
} 

function hideAp() { 
    if (document.layers) { 
     document.layers.pa.visibility = 'hide'; 
    } else if (document.all) { 
     document.all.pa.style.visibility = 'hidden'; 
    } else if (document.getElementById) {  
     document.getElementById("pa").style.visibility = 'hidden'; 
    } 
} 

function showAp() { 
    state=typeof tPos; 

    if(state=='undefined') { 
     tPos = h; 
    } 

    if(tPos < t) { 
     tPos+=25; 
     if (document.layers) { 
      document.layers.pa.top = tPos+"px"; 
     } else if (document.all) { 
      document.all.pa.style.top = tPos+"px"; 
     } else if (document.getElementById) { 
      document.getElementById("pa").style.top = tPos+"px"; 
     } 
    } 

    if(timer!=null) clearInterval(timer); 
    timer = setTimeout("showAp()",30); 
} 

function getoPos() { 
    if (document.layers) { 
     alert(document.layers.pa.top); 
    } else if (document.all) { 
     alert(document.all.pa.style.top); 
    } else if (document.getElementById) { 
     alert(document.getElementById("pa").style.top); 
    } 
} 

function setLeft() { 
    if (document.layers) { 
     document.layers.pa.left = ((window.innerWidth/2) - (w/2))+"px"; 
    } else if (document.all) { 
     document.all.pa.style.left = ((document.body.offsetWidth/2) - (w/2))+"px"; 
    } else if (document.getElementById) { 
     document.getElementById("pa").style.left = ((window.innerWidth/2) - (w/2)) + "px"; 
    } 
} 
+2

不是在頁面加載時調用'startAp()',而是執行'setTimeout(startAp,1000)'(1秒延遲)。 PS。你沒有在任何地方使用jQuery,那麼你爲什麼要標記它? – ori 2012-02-05 20:43:58

回答

0

使用setTimeout funcion一些延遲後執行的功能。例如

setTimout(showApp, 6000) // time is in milliseconds 
+0

謝謝,這很好!非常感激。 – user1191117 2012-02-05 21:09:06

+0

然後你應該把答案標記爲接受:) – Matthew 2012-02-05 21:10:15