Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
630 B
1
Indexable
Never
<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>
Leave a Comment