const images = document.querySelectorAll('img') const callback = (entries) => { entries.forEach(enter =>{ if(enter.isIntersectiing){ const image = enter.target; const data_src = image.getAttribute('data_src') image.setAttribute('src',data_src) observer.unobserve(img) } }) } const observer = new IntersectionObserver(callback) images.forEach( image =>{ observer.observer(img) })