Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
const observer = new IntersectionObserver(entries => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add("visible"); // Load lazy image const img = entry.target; if (img.dataset.src) { img.src = img.dataset.src; observer.unobserve(img); } } }); }, { threshold: 0.1 }); document.querySelectorAll(".lazy").forEach(el => observer.observe(el));
Result
Open