内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用
根据IE8的哪种模式,我会得到不同的高度和宽度。我已经尝试过标准的javascript和jQuery,但两者都返回不同的结果。
$('body').width = 1239 $('body').height = 184 document.body.clientWidth = 1231 document.body.clientHeight = 176
在标准中
$('body').width = 1260 $('body').height = 182 document.body.clientWidth = 1254 document.body.clientHeight = 176
任何想法,如何得到一个价值不变的IE8模式。
这个问题可能是由于滚动条包含在宽度和高度中,而不管它们是否存在。我没有IE(在Mac上),所以无法验证。其中使用以下代码:
// Make the overlay the size of the body var $body = $(this.ie6 ? document.body : document); // using document in ie6 causes a crash $('#lightbox-overlay').css({ width: $body.width(), height: $body.height() }); // ... some code ... // Get the window dimensions var $window = $(window); var wWidth = $window.width(); var wHeight = $window.height();
叠加显示正确。与本地结果相比,我相信jQuery的宽度和高度的结果,因为jQuery自然应该考虑浏览器的任何古怪之处。
需要注意的是,上面的Lightbox脚本倾向于$(document)
过关$(document.body)
出于某种原因
试着给你的身体#页:
function getPageHeight() { var pageHeight = document.getElementById('page').offsetHeight; var pageWidth = document.getElementById('page').offsetWidth; alert(pageHeight); alert(pageWidth); }