Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
91
rated 0 times [  94] [ 3]  / answers: 1 / hits: 137869  / 15 Years ago, wed, april 1, 2009, 12:00:00

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 or display: 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.


More From » dom

 Answers
160

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.


From MDN's documentation:



The elementFromPoint() method—available on both the Document and ShadowRoot objects—returns the topmost Element at the specified coordinates (relative to the viewport).



[#99770] Wednesday, March 25, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cruzs

Total Points: 710
Total Questions: 113
Total Answers: 100

Location: Nepal
Member since Sat, Jul 18, 2020
4 Years ago
cruzs questions
Thu, Nov 26, 20, 00:00, 4 Years ago
Wed, Oct 28, 20, 00:00, 4 Years ago
Wed, Aug 19, 20, 00:00, 4 Years ago
Sun, Aug 2, 20, 00:00, 4 Years ago
;