2012-01-11 126 views
0

有什么方法可以改变车身高度。我试过了:更改车身尺寸高度

if(document.body.scrollHeight > document.getElementById('DIVBODY').scrollHeight) { 
    document.body.scrollHeight = document.getElementById('DIVBODY').scrollHeight 
} 

但它不起作用。 我动态地改变我的DIVBODY内容,我不希望我比div DIVBODY大。

体和DIV:

<body background="images/grey-lines.png" style="overflow-y:scroll" > 

<div id="DIVBODY" style="max-width:1102px; margin: auto; width: expression(Math.min(parseInt(this.offsetWidth), 1102)); height:100%; text-align:center; align:center; 
background-image: url(bg/wood-3.jpg) ; background-color:#af7746; background-attachment:fixed; background-position: top center ; background-repeat: repeat; border-left: 1px solid black; border-right: 1px solid black; height: auto; min-height: 100%; _height: 100%;"> 
+0

请出示只是document.body.scrollHeight和的document.getElementById( 'DIVBODY')。scrollHeight属性之前,你的 “IF” 调试它 – clement 2012-01-11 19:13:29

回答

0

MDN

scrollHeight是一个只读属性。

你可以尝试element.scrollTopelement.style.height来完成你想要

+1

@MDN什么它看起来像你可以放大身高,例如: 'document.getElementsByTagName('body')[0] .style.height =“40000px”;' 但是你不能减少它,即使内容如果比内容大! 任何想法,以减少身高? – defacto 2012-01-11 20:10:38

+0

即时与相同的怀疑比事实 – 2012-10-19 12:38:43