2013-04-30 29 views
0

我試圖在我的網站上合併一個新的幻燈片。除了「height =」80%「」選項外,幻燈片還有我需要的所有內容,即我希望幻燈片能夠與瀏覽器一起縮放,因爲新的網站設計會像android應用程序那樣排序;完全身臨其境。javascript setTimeout在包含createElement後停止工作

因爲幻燈片本身沒有這個選項,所以我創建了一個javascript代碼,它會每2秒檢查一次文檔/瀏覽器窗口的大小,並重新載入/調整幻燈片本身的大小,使其始終適合屏幕。但是,問題是JavaScript將只運行一次,onload,並且在我將特定的代碼字符串粘貼到腳本後不會調用「setTimeout」。

所以,問題是,setTimeout的實際停止工作,所以它已經工作過,之後我包括這串代碼:

var thescript = document.createElement("script"); 
thescript.type = "text/javascript"; 
thescript.innerHTML="jQuery.flashgallery('gallery/ArtGallery.swf', 'gallery/gallery.xml', {width: '100%', height: '"+calcheight+"px', background: '#000000'});"; 
document.getElementById('galleryid').appendChild(thescript); 

完整的JavaScript檢查功能是在這裏:

function getDocSpecs() { 

    clearTimeout(t); 
    var D = Math.max(
     Math.max(document.body.scrollHeight, document.documentElement.scrollHeight), 
     Math.max(document.body.offsetHeight, document.documentElement.offsetHeight), 
     Math.max(document.body.clientHeight, document.documentElement.clientHeight)); 

    var Le = Math.max(
     Math.max(document.body.scrollWidth, document.documentElement.scrollWidth), 
     Math.max(document.body.offsetWidth, document.documentElement.offsetWidth), 
     Math.max(document.body.clientWidth, document.documentElement.clientWidth)); 

    calcheight = (0.80 * D); 
    alert(preheight + "_" + prewidth + "_" + D + "_" + Le + "_"); 
    if (preheight != D || prewidth != Le) { 

     var thescript = document.createElement("script"); 
     thescript.type = "text/javascript"; 
     thescript.innerHTML = "jQuery.flashgallery('gallery/ArtGallery.swf', 'gallery/gallery.xml', {width: '100%', height: '" + calcheight + "px', background: '#000000'});"; 
     document.getElementById('galleryid').appendChild(thescript); 
    } 


    preheight = D; 
    prewidth = Le; 

    t = setTimeout('getDocSpecs()', 2000); 
} 

這兩個似乎不喜歡對方:

var thescript = document.createElement("script"); 
thescript.type = "text/javascript"; 
thescript.innerHTML="jQuery.flashgallery('gallery/ArtGallery.swf', 'gallery/gallery.xml', {width: '100%', height: '"+calcheight+"px', background: '#000000'});"; 
document.getElementById('galleryid').appendChild(thescript); 

t = setTimeout('getDocSpecs()', 2000); 

我試着先裝入幻燈片,然後調用該函數來欺騙它,增加了點擊激活文本,調用多種功能等

+0

爲什麼你認爲你需要創建'