silvester-23/static/lazy.js
2023-11-20 17:13:17 +01:00

17 lines
484 B
JavaScript

window.onload = function () {
// Get all <img> elements with loading="lazy"
var lazyImages = document.querySelectorAll('img[loading="lazy"]');
console.log(lazyImages)
// Loop through each image and apply the fade-in effect
lazyImages.forEach(function (lazyImage) {
lazyImage.classList.add('lazy-image');
var img = new Image();
img.src = lazyImage.src;
img.onload = function () {
lazyImage.style.opacity = 1;
};
});
};