fix: lazy loading

This commit is contained in:
max_richter 2023-11-20 17:13:17 +01:00
parent 871c6d6959
commit a8cf13157b

View File

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