Does IntersectionObserver consider visible a div that is inside the viewport, but covered by another div?

90 Views Asked by At

I'm having issues with Intersection Observer and don't really know what's the problem. So I've got a question as I'm curious:

  • Let's imagine 2 divs A & B
  • A & B are both 100vw by 100vh (full viewport)
  • They're both moving together, same position
  • B is above A and fully covers A

Is Intersection Observer supposed to consider A as visible when it is inside the viewport? Even though it's fully covered?

By "visible" I mean isIntersecting = true

1

There are 1 best solutions below

1
Kaiido On BEST ANSWER

Yes it does.
To compute the intersection of a Target Element and the Root the UA only has to look at the Target element and the Root element (which is an ancestor node). Siblings don't matter, whether they cover the Target or not.

Determining if an element is covered by another element would bring some security considerations into the mix. For instance you could use it to determine if a certain image contains transparency or not, which in turn could help determining other privacy related contents. So while it's been talked about before, I'm not sure it's still on track.