jQuery-如何检测当前是否在视口之外? [英] jQuery - How to detect if an item is currently outside of the viewport?
问题描述
我正在构建一个页面,该页面将使用ajax更新主要内容区域.用户将单击左侧菜单栏中的项目,以使用搜索结果将div更新到右侧.
I'm building a page that will be using ajax to update a main content area. Users will be clicking on items from a left hand menu bar to update a div to the right with search results.
我想检测用户是否向下滚动到目前为止,从而导致右侧结果div移动到视口之外-但是有没有检测到这一点?
I want to detect if a user has scrolled down so far causing the right-hand-side results div to moved outside the viewport -- but has does one detect that?
推荐答案
没有测试/跨浏览器保证/示例代码,但请查看 $elem.offset().top
与 $(document).scrollTop()
-可能是您的解决方案.
No testing/cross browser assurances/example code but take a look at $elem.offset().top
vs the $(document).scrollTop()
- Might be your solution.
您可能还需要元素的 .height()
和window
.
You might need the .height()
of the element and the window
as well.
freenode上#jQuery中的Brodingo只是将我链接到了一个可能会简化它的视口选择器插件.
Brodingo in #jQuery on freenode just linked me to a Viewport Selectors plugin that might simplify it.
这篇关于jQuery-如何检测当前是否在视口之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!