<img loading="lazy" src="https://via.placeholder.com/320x200" alt="Lazy loaded image" />
<img src="image.png" loading="lazy" alt="…" style="height:200px; width:200px;">
<img src="image.png" loading="lazy" alt="…" width="200" height="200">
const imgTargets = document.querySelectorAll("img[data-src]");
const imgObserve = function (entries, observer) {
const [entry] = entries;
console.log(entry);
//replace src with data-src
if (!entry.isIntersecting) {
return;
}
entry.target.src = entry.target.dataset.src;
//load event
entry.target.addEventListener("load", function () {
entry.target.classList.remove("lazy-img");
});
observer.unobserve(entry.target);
};
const imgOptions = {
root: null,
threshold: 0,
rootMargin: "200px",
};
const imgObserver = new IntersectionObserver(imgObserve, imgOptions);
imgTargets.forEach(function (img) {
imgObserver.observe(img);
});
Code Example |
---|
Html :: trash icon html |
Html :: registration form template bootstrap |
Html :: svg as button |
Html :: html css text style on a word |
Html :: html to powerpoint |
Html :: flutter web load html |
Html :: block level elements |
Html :: how to put your email in html |
Html :: how to add css file in wordpress |
Html :: favicon.ico html |
Html :: ng-src |
Html :: Server side validations Laravel |
Html :: tutorialspoint html |
Html :: html table basics |
Html :: cahnge bootstrap navbar color |
Html :: img srcset |
Html :: css image slideshow |
Html :: picsum |
Html :: favicon x shortcut icon |
Html :: markdown background colour |
Html :: bootstrap nav nav tabs float right |
Html :: import ionicons |
Html :: how to make html element center of the screen |
Html :: tailwind rounded top left |
Html :: how to install font-aweseome usin npm |
Html :: name input html |
Html :: how to add bg html |
Html :: ignor < in html |
Html :: css how to place an icon on a photo |
Html :: how to make email required in html |