简体   繁体   English

如何在给定点直接或通过另一个元素的腔检测哪个元素可见/在顶部?

[英]How to detect which element is visible/on-top directly or through the cavities of another element at a given point?

Suppose I have a div (background set to blue), and inside it, there is a <h1> containing some text in white. 假设我有一个div(背景设置为蓝色),并且在其中有一个<h1>其中包含一些白色文本。

Using the javascript function elementFromPoint() , I can find which element is currently at a given coordinate(x,y), but this function only checks the bounds, and not actual visibility. 使用javascript函数elementFromPoint() ,我可以找到当前处于给定坐标(x,y)的元素,但是此函数仅检查边界,而不检查实际可见性。 eg if <h1> contains the text "HELLO" , then from inside the "O", the background (blue) div is actually visible, but the elementFromPoint() function still detects the <h1> tag there, because it only checks the bounding-box of the <h1> . 例如,如果<h1>包含文本"HELLO" ,则实际上从背景(蓝色)div是可见的,但是elementFromPoint()函数仍然在其中检测<h1>标记,因为它仅检查<h1>边界框。

Is there any javascript function/library using which I can detect the actually visible object at a point? 是否有任何javascript函数/库可用来检测某个点上实际可见的对象? (See the picture below for the problem I'm facing) (有关我面临的问题,请参见下面的图片)

看到下面的图片,我想要一个可以正确检测DIV的函数

Use visible selector : 使用可见选择器

$(selector).is(':visible');

You have html like this: 你有这样的HTML:

<div><h1></h1></div>

So, applying visibility hidden to div it still shows the h1 tag. 因此,将隐藏的可见性应用于div仍会显示h1标签。 demo 演示

And if you apply display none to div then h1 tag is hidden. 如果将display none应用于display,则h1标签将被隐藏。 demo 演示


So, you might be having visibility property instead of display. 因此,您可能具有可见性属性而不是显示属性。 Thus change it with display: none; 因此,用display: none;更改它display: none;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM