2013-02-13 75 views
0

我知道這個問題已經被問了很多,我向你保證我已經閱讀了大部分答案。但是,就我而言,它並沒有爲我工作。我目前正在此:如何動態更改Javascript高度

window.onload = function(){ 

    var winWidth = parseInt(window.innerWidth); 
    var winHeight = parseInt(window.innerHeight); 

    document.getElementById("copyRight").innerHTML = winHeight; 
    //This is so I could make sure the height was actually changing. It is. 

    document.getElementById("grandeContain").style.width = winWidth-15+"px"; 
    document.getElementById("grandeContain").style.height = winheight+"px"; 
    document.getElementById("contain").style.width = winWidth-105+"px"; 
    document.getElementById("contain").style.height = winHeight-90+"px"; 
    document.getElementById("outside").style.width = winWidth-105+"px"; 
    document.getElementById("outside").style.height = winHeight-90+"px"; 
    document.getElementById("aroundToolBar").style.height = winHeight-90+"px"; 
} 

但是,無論我做什麼高度不改變onload(我也有這個複製並粘貼到一個onresize功能,並且也不管用)。寬度部分工作正常(不只是因爲這是div的默認設置;我已經根據window.innerWidth基於window.innerWidth進行了多種不同寬度的測試,並且它已更改),但高度拒絕更改。我究竟做錯了什麼?我一直在動態地改變身高方面遇到麻煩,如果我能夠一勞永逸地解決這個問題,那將是一件好事。

而且,如果CSS有什麼關係呢,在div樹是這樣的:grandeContain>contain>(aroundToolBar+outside)其中containposition:relativearoundToolbarfloat:leftwidth:125pxoutsideposition:relativemargin 0 0 0 125px

有沒有人知道我在做什麼錯在這裏?

另外,105s和90s在那裏soley,因爲grandeContain div中的頁眉和頁腳與他們的兄弟姐妹包含在一起。

+0

那麼,你有什麼異常?或者你可以做一個演示? – Bergi 2013-02-13 20:18:20

回答

1

你檢查了螢火蟲的錯誤嗎?好像就行了:

document.getElementById("grandeContain").style.height = winheight+"px"; 

你有一個錯字:應爲winHeight+"px",而不是winheight+"px";可能會導致一個變量未定義的錯誤。