SOURCE

const images = document.querySelectorAll('img')
const fun = (entries)=>{
    entries.forEach(image => {
        if(image.isIntersection){
            const target = entry.target
            const datasrc = target.getAttribute("data-src")
            image.setAttribute(datasrc)
            observer.unobserve(image)
        }
    })
}
const observer = new IntersectionObserver(fun)
images.forEach((image)=>{
    observer.observe(image)
})
console 命令行工具 X clear

                    
>
console