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