【发布时间】:2013-07-13 10:55:20
【问题描述】:
我目前在获取 html 元素的高度时遇到了一些问题,似乎在调整窗口大小时它没有得到更新。我尝试使用“高度:自动”重置 html,但这似乎没有帮助。
宽度正常,但高度没有更新。
有解决这个问题的办法吗?
提前致谢!
JQuery:
function UpdateLeftBar() {
// Reset
$('html').height('auto');
// Get the height of the window and minus the header and left top elements
height = $('html').height() - 85 - 56 + 29;
width = $('html').width() - 300;
// Set the div to the new height
$('#leftContentBottom').css({ 'height': height });
$('#middleContent.span10').css({ 'width': width });
console.log(height);
}
$(window).resize(function () {
UpdateLeftBar();
});
真的很奇怪,我注意到它有 80% 的时间会更新,但如果你双击窗口,它不会调整大小。
修复:您应该获取窗口的高度,而不是获取 html 的高度。这解决了我的问题。
【问题讨论】:
-
邮政编码。最好在 jsfiddle 中。
-
我会做一个现场演示,等等!
-
很遗憾,我的虚拟主机有问题,所以我无法设置现场演示。如果有任何问题,请随时提问! @m90,只是 html5 版本:
-
console.log(height);的输出是什么?