微信浏览器window.onscroll无效

搞一个公众号html网页投票,下拉到底部加载更多
发现在浏览器中window.onscroll可以正常获取滚动的值,但是在手机微信里window.onscroll就失效了。
换成window.addEventListener(“scroll”, function(){})和jquery的$(window).scroll(function(){都没用。
最后换成IntersectionObserver才算可以了。
这微信内置浏览器是真tm的坑啊。

const loader = document.querySelector('#loader');
// 创建一个IntersectionObserver实例
const observer = new IntersectionObserver(entries => {
  // 如果触发了交叉状态且交叉的目标是触发加载更多内容的占位符元素
  if (entries[0].isIntersecting && entries[0].target === loader) {
    console.log('加载更多内容');
  }
});
// 对观察的目标元素进行监听
observer.observe(loader);

猜你喜欢

转载自blog.csdn.net/woshiabc111/article/details/132903062