Untitled
unknown
plain_text
2 years ago
630 B
4
Indexable
<script>
document.addEventListener("DOMContentLoaded", function() {
const imageObserver = new IntersectionObserver((entries, imgObserver) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const lazyImage = entry.target
console.log("lazy loading ", lazyImage)
// lazyImage.src = lazyImage.dataset.src
if (!lazyImage.hasAttribute("loading")) {
lazyImage.setAttribute('loading', 'lazy');
}
}
})
});
const arr = document.querySelectorAll('.post-content img')
arr.forEach((v) => {
imageObserver.observe(v);
})
})
</script>Editor is loading...
Leave a Comment