为什么jquery .height()在chrome上得到不同的结果? [英] why jquery .height() get a different result on chrome?

查看:102
本文介绍了为什么jquery .height()在chrome上得到不同的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is how chrome show the width and height of the div :

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

which is correct, in fact the height is 1466. But, if I do this :

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

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

it prints 1418. It doesnt have any padding/margin. Why? And how can I fix it?

推荐答案

这是因为在DOMReady上,某些图像未完全加载.您应该在窗口加载时调用高度.

That's because on DOMReady some images are not loaded completely. You should call the height on window load.

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

您也可以使用outerHeight:

获取匹配元素集合中第一个元素的当前计算高度,包括填充,边框和可选的边距.返回值的整数表示形式(无"px");如果在一组空元素上调用,则返回null.

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());

这篇关于为什么jquery .height()在chrome上得到不同的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆