silvester-23/static/lazy.js

17 lines
530 B
JavaScript
Raw Normal View History

2023-11-20 16:57:04 +01:00
window.onload = function () {
// Get all <img> elements with loading="lazy"
var lazyImages = document.querySelectorAll('img[loading="lazy"]');
2023-11-20 16:16:23 +01:00
2023-11-20 16:57:04 +01:00
console.log(lazyImages)
2023-11-20 16:16:23 +01:00
2023-11-20 16:57:04 +01:00
// Loop through each image and apply the fade-in effect
lazyImages.forEach(function (lazyImage) {
console.log(lazyImage)
var img = new Image();
img.src = lazyImage.src;
img.onload = function () {
lazyImage.style.opacity = 1;
};
});
};