const images = document.querySelectorAll('img'); const observer = new IntersectionObserver(entries =>{ entries.forEach(entry => { if(entry.isIntersecting) { const img = entry.target; const data_src = img.getAttribute('data-src'); img.setAttribure('src', data_src); observer.unobserve(img); } }) }) images.forEach(image => { observer.observe(image) })