WeChat browser window.onscroll is invalid

Build a public account html webpage to vote, scroll down to the bottom to load more
I found that window.onscroll can get the scrolling value normally in the browser, but in WeChat on the mobile phone, window. onscroll is invalid.
Replace with window.addEventListener(“scroll”, function(){}) and jquery’s $(window).scroll(function(){, both of which are useless.
Finally, it is enough to change to IntersectionObserver.
This WeChat built-in browser is really a trap.

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

Guess you like

Origin blog.csdn.net/woshiabc111/article/details/132903062