如何使用JavaScript检查元素是否真实可见? [英] How do I check if an element is really visible with JavaScript?
问题描述
在JavaScript中,您如何检查元素是否实际可见?我不仅仅意味着检查可见性
和显示
属性。我的意思是,检查元素不是
-
可见性:隐藏
或display:none
- 另一个元素下方
- 滚动屏幕边缘
出于技术原因,我不能包含任何脚本。然而,我可以使用原型,因为它已经在页面上。
对于点2。
我看到没有人建议使用 document.elementFromPoint(x,y)
,对我来说,测试元素是否嵌套或隐藏的最快方法。您可以将目标元素的偏移量传递给函数。
以下是 elementFromPoint 。
In JavaScript, how would you check if an element is actually visible?
I don't just mean checking the visibility
and display
attributes. I mean, checking that the element is not
visibility: hidden
ordisplay: none
- underneath another element
- scrolled off the edge of the screen
For technical reasons I can't include any scripts. I can however use Prototype as it is on the page already.
For the point 2.
I see that no one has suggested to use document.elementFromPoint(x,y)
, to me it is the fastest way to test if an element is nested or hidden by another. You can pass the offsets of the targetted element to the function.
Here's PPK test page on elementFromPoint.
这篇关于如何使用JavaScript检查元素是否真实可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!