6

Can new IntersectionObserver() be used to detect if a user is at the top of the page (scrollY = 0) VS. when scrollY > 0 (user has scrolled down)?

Because I tried this and can't get it to work:

var myObs = new IntersectionObserver(function (entry) {
    if ( entry.intersectionRatio > 0 ) {
        console.log('> 0');
    } else {
        console.log('< 0');
    }
}, { threshold: [0], rootMargin: '0px 0px', });

myObs.observe( document.body );
user1945912
  • 597
  • 3
  • 9
  • 19

0 Answers0