I am working on website at the moment, that has some native lazy loading of images using IntersectionObserver
the images that I am trying to load are loaded in via ajax as a result I don't think they are "loaded" into DOM on page load, and therefore the images cannot be lazyloaded, by lazy load codes looks like this,
const io = new IntersectionObserver((entries, observer) => {
// console.log(entries)
entries.forEach(entry => {
console.log('😍');
if (entry.isIntersecting) {
console.log('intersecting');
const img = entry.target;
const src = img.getAttribute('data-lazy');
img.setAttribute('src', src);
img.classList.add('fade');
observer.disconnect();
}
});
Is it possible to lazy load images that are part of content that is loaded via ajax?