8

这篇文章与这个有关。请考虑阅读它。:-)

在我链接到的帖子中,我认为如果一个 div 的可见高度大于另一个 div 的可见高度,则我的问题的解决方案是更改链接的目标。在我的布局中,我所指的所有 div 的高度均为 1100 像素。但这不是我想要得到的。我希望脚本获取当前对访问者可见的 div 的高度,而不是它的实际高度。有没有办法使用jQuery来做到这一点?

提前致谢!

4

3 回答 3

8

您可以做的是将元素位置放在其父容器的顶部,然后从父容器高度减去它。这将为您提供元素的可见高度。

$('#container').height() - $('#overflow').position().top

这是一个显示这一点的小提琴。

于 2013-01-02T17:24:15.183 回答
1

用另一个 DIV 包装视口 DIV 的内容。定位该 DIV 以读取所有内容的高度,如下所示:

jQuery: $('div#contents').height();

布局:

<div id="viewport">
  <div id="contents">...all your div contents...</div>
</div>

希望这可以帮助。祝你好运。

于 2013-01-02T17:15:07.707 回答
-1

Do you have to use a fixed 1100px height? Cause you could also specify a max-height:1100px; and a height:100%; Depending on what you want to put inside the div you can of course get the current height by

$('.divclass').height();
于 2013-01-02T17:18:49.883 回答