【问题标题】:Change body size height改变体型高度
【发布时间】:2012-02-08 03:15:34
【问题描述】:

有什么办法可以改变身高。我试过了:

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

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

body 和 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%;">

【问题讨论】:

  • 请在“IF”之前简单显示 document.body.scrollHeight 和 document.getElementById('DIVBODY').scrollHeight 以进行调试

标签: javascript html height document-body


【解决方案1】:

来自MDN

scrollHeight 是只读属性。

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

【讨论】:

  • @MDN 看起来你可以放大身体高度,例如:document.getElementsByTagName('body')[0].style.height = "40000px" ; 但是你不能减少它,即使内容如果 大于内容!有降低身高的想法吗?
  • 我与事实上的怀疑相同
猜你喜欢
  • 2015-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多