JQuery的,如果一个div在页面上可见? [英] Jquery if a div is visible on page?

查看:88
本文介绍了JQuery的,如果一个div在页面上可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



作为导航栏的一部分,我希望它突出显示某个链接 if >某个其他div在页面上可见。



我有一种感觉,jquery会这样做的。

这是我的意思的一个例子。
请注意,如果导航链接显示在页面上,它们的链接部分将突出显示。



任何人都可以帮忙吗?

$如果元素在DOM中可见,其他答案将返回true - 即使它们的样式为 code> display:none 并且实际上并不是可见的。



如果您想查看元素是否目前在视口中可见,一种解决方案可能是使用 Viewport Selectors for jQuery。然后,您可以使用 $()来检查元素当前是否在视口中(IE物理可见) :in-viewport)选择器。



以下是使用它的一个示例


I am trying to make a one page website.

As part of the navigation bar i would like it to highlight a certain link if a certain other div is visible on the page.

I have a feeling jquery will do this.

Here is an example of what i mean. Notice how the navigation links highlight if the section they link to is visible on the page

Can anyone help??

解决方案

The other answers will return true if an element is visible in the DOM - even if they're styled as display:none and not actually 'visible' in a visual sense.

If you want to see if an element is currently visible in the viewport, one solution could be to look into using using Viewport Selectors for jQuery.

Then, you could check whether an element is currently in the viewport (I.E. physically visible) using the $(":in-viewport") selector.

Here's an example of it being used.

这篇关于JQuery的,如果一个div在页面上可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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