【发布时间】:2013-12-21 13:48:52
【问题描述】:
目的:当内部内容超过最大高度时添加滚动条,否则设置为隐藏溢出(设置overflow-y: scroll时显示滚动条)
上下文:这是在一个win8.1应用程序中(所以ie11三叉戟)
问题:#table-wrapper div 上的style.maxHeight 设置为''
我的css
#threads table {
width: 100%;
}
#table-wrapper {
max-height: 600px;
}
我的Js
var threadTable = document.getElementById('thread-table');
var tableWrapper = document.getElementById('table-wrapper');
if (threadTable.clientHeight > tableWrapper.style.maxHeight) {
tableWrapper.style.overflowY = 'scroll';
} else {
tableWrapper.style.overflowY = 'hidden';
}
我的html
<div id="threads" class="info">
<h3>IE Build Info</h3>
<div id="table-wrapper">
<table id="thread-table"></table>
</div>
</div>
建议会有所帮助。可能有更好的方法来做我正在做的事情,但我不希望滚动条(即使它在一段时间后消失)在不需要时出现。
【问题讨论】:
-
.style对象仅显示直接在元素上设置的 CSS 属性。 -
我在发布之前正在阅读 SO,有人说如果设置了 CSS 高度,则应该设置
style.height?他们错了吗? -
是的,他们错了。
-
除非在 JS 本身中设置,否则没有办法学习应用于对象的 css 样式吗?
-
搜索
getComputedStyle()
标签: javascript css internet-explorer internet-explorer-11