IntersectionObserver API兼容性:
部分代码展示:
// 懒加载处理const imgsElem = document.querySelectorAll('img');const topElem = document.querySelector('#top');// IntersectionObserverconst Observer = new IntersectionObserver((entries, observer) => {entries.forEach((entry) => {if (entry.isIntersecting) {let img = entry.target;img.src = img.dataset.srcobserver.unobserve(img)}})})// 绑定监听APIimgsElem.forEach((img) => {Observer.observe(img)})
具体代码请点击InsCode去详细查看!!!