一切似乎很好,jQuery.height()
和jQuery.innerHeight()
与溢出属性无关。他们会回到高处,而不仅仅是可见的部分。
如果你想知道内容高度,你必须使用scrollHeight
。这scrollHeight
是一个普通的JavaScript属性您不必使用jQuery
document.getElementById("wrapper").scrollHeight;
或者你可以使用jQuery选择
见工作的jsfiddle:http://jsfiddle.net/scgz7an5/1/
注意
$('#wrapper').scrollHeight;
返回undefined。
UPDATE
你忘了浮动元素中最重要的组成部分。你忘了清除它们。
看看这个jsfiddle,是对你的编辑,但是清除了浮动元素。在那里您会看到scrollHeight
和jQuery.height()
的不同值。看到.structureContent
是有滚动条的,不是.content
也不是.width100
。
.structureContent
有overflow:auto
您看到的滚动条来自它。
http://jsfiddle.net/L2bxmszv/5/
我加入这个类来清除浮动元素。
.clearfix:before,
.clearfix:after, {
content: '\0020';
display: block;
overflow: hidden;
visibility: hidden;
width: 0;
height: 0; }
.clearfix:after {
clear: both; }
.clearfix {
zoom: 1; }
输出是这样的:
.content
324 for scrollHeight
324 for clientHeight
324 for jQuery.height()
.structureContent
324 for scrollHeight
276 for clientHeight
276 for jQuery.height()
查看关于浮动元素和他们在这里清除了一大篇:http://css-tricks.com/all-about-floats/
您使用Jquery的哪个'div'来获得'height'?容器一个,还是内部的? – LcSalazar 2014-09-01 16:12:03
容器一个,里面有几个内部的div,它们是从数据库中产生的。 – 2014-09-01 16:27:07