微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么jquery .height()在chrome上得到不同的结果?

这是chrome显示div的宽度和高度的方式:

这是正确的,实际上高度是1466.但是,如果我这样做:

$(document).ready(function () {
    console.log($('#container-altezza-fisso').height());
});

它打印1418.它没有任何填充/边距.为什么?我该如何解决

解决方法

那是因为在Domready上有些图像没有完全加载.你应该在窗口加载时调用高度.
$(window).load(function(){
    console.log($('#container-altezza-fisso').height());
})

你也可以使用outerHeight:

Get the current computed height for the first element in the set of matched elements,including padding,border,and optionally margin. Returns an integer (without “px”) representation of the value or null if called on an empty set of elements.

console.log($('#container-altezza-fisso').outerHeight());

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐