Skip to content

Instantly share code, notes, and snippets.

@Kcko
Last active August 1, 2024 08:04
Show Gist options
  • Save Kcko/831edab47e98828c2e8cd685615f0e4c to your computer and use it in GitHub Desktop.
Save Kcko/831edab47e98828c2e8cd685615f0e4c to your computer and use it in GitHub Desktop.
document.addEventListener('DOMContentLoaded', () => {
let lazyImages = document.querySelectorAll('.lazyload');
let observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
let img = entry.target;
img.src = img.dataset.src;
observer.unobserve(img);
}
});
});
lazyImages.forEach(img => {
observer.observe(img);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment