在尝试确定多个div的高度时,与Safari检查器报告的内容相比,在计算网站的脚本负载时,我发现Safari(v10.1.1)产生的结果存在显着差异 . 到目前为止,这个问题还没有出现在Chrome或Firefox中 .

在测试中,我只是针对一个有问题的div(它有一些子元素):

console.log(document.getElementById('foo1').clientHeight);

控制台为此特定div返回的结果为329,远大于预期 . 但是,当我查看Safari检查器中的节点时,clientHeight报告为175 - 这是预期的准确数字 . 同样,如果我直接在Safari的控制台命令行中运行相同的命令,则返回正确的数字 .

通过一些进一步的测试,似乎我的样式表导致了问题,因为如果我暂时删除它,返回的结果是准确的 .

有没有人知道为什么会出现这种情况?我'm just surprised that the correct numbers are reported by Safari except when executed on script load and why the stylesheet might force the discrepancy. Is it possible that the loading order of the script and stylesheets as anything to do with the issue? Note that I' m在页面底部加载我的脚本,在结束之前 </body>

干杯,并提前感谢 .