Javascript IntersectionObserver检测是否滚动>;身体上的0?
是否可以使用Javascript IntersectionObserver检测是否滚动>;身体上的0?,javascript,intersection-observer,Javascript,Intersection Observer,是否可以使用newintersectionobserver()检测用户是否位于页面顶部(scrollY=0)而不是scrollY>0(用户已向下滚动) 因为我试过了,但没能成功: var myObs = new IntersectionObserver(function (entry) { if ( entry.intersectionRatio > 0 ) { console.log('> 0'); } else { console.
newintersectionobserver()
检测用户是否位于页面顶部(scrollY=0)而不是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 );
var myObs=新的IntersectionObserver(函数(条目){
如果(entry.intersectionRatio>0){
console.log('>0');
}否则{
console.log(“<0”);
}
},{threshold:[0],rootMargin:'0px 0px',});
myObs.observe(document.body);