0
<div style="display: none;">
   <span>Hello</span>
</div>
const div = document.querySelector('div');
// getComputedStyle(div).display === 'none';

const span = document.querySelector('span');
// how can I tell if the span is shown?

In the code above, is there any easy way to tell whether the span is shown in the window or not?

Safwan Samsudeen
  • 1,645
  • 1
  • 10
  • 25

1 Answers1

0

The modern way to do this is to use an intersection observer.

let options = {
  root: document.querySelector('#scrollArea'),
  rootMargin: '0px',
  threshold: 1.0
}

let observer = new IntersectionObserver(callback, options);
David Bradshaw
  • 11,859
  • 3
  • 41
  • 70
  • This is not related to my question, but it's very interesting. It looks like it will notify when some value changes? –  Aug 27 '20 at 08:39