使用jquery获取元素的可见高度而不是其实际高度 [英] Get visible height of an element instead of its actual height with jquery

查看:805
本文介绍了使用jquery获取元素的可见高度而不是其实际高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This post is related to this one. Please consider reading it as well. :-)

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

In the post I linked to, I figured the solution to my problem would be to change the target of a link if the visible height of a div is greater than that of another div. In my layout, all the divs I'm referring to have a height of 1100px. But that's not what I want to get. I'd like the script to get height of the div that is currently visible to the visitor, not its real height. Is there a way to do it using jQuery?

提前致谢!

推荐答案

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

What you can do is take the elements position to the top of its parent container and then minus it from the parents container height. That will give you the visible height of the element.

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

这是小提琴显示了这一点。

这篇关于使用jquery获取元素的可见高度而不是其实际高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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