IntersectionObserver 检测主体上是否滚动Y > 0?

use*_*912 7 javascript intersection-observer

new IntersectionObserver()用于检测用户是否位于页面顶部 (scrollY = 0) VS. 当scrollY > 0(用户已向下滚动)时?

因为我尝试了这个但无法让它工作:

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 );
Run Code Online (Sandbox Code Playgroud)