fix: lazy load portraits

This commit is contained in:
max_richter 2023-11-20 16:51:33 +01:00
parent 06bcdae2d1
commit 43c862fbfd
2 changed files with 15 additions and 19 deletions

View File

@ -25,8 +25,3 @@ img.lazy-image {
opacity: 0;
transition: opacity 0.3s ease;
}
img.lazy-image.loaded {
opacity: 1;
z-index:-1;
}

View File

@ -1,16 +1,17 @@
window.onload = function () {
// Get all <img> elements with loading="lazy"
var lazyImages = document.querySelectorAll('img[loading="lazy"]');
var lazyImages = [...document.querySelectorAll("img[loading='lazy']")];
// Loop through each image and apply the fade-in effect
lazyImages.forEach(function (lazyImage) {
lazyImage.style.opacity = 0;
lazyImage.classList.add("lazy-image")
for (let i = 0; i < lazyImages.length; i++) {
var element = lazyImages[i];
element.classList.add("lazy-image")
element.onload = function(){
element.classList.add("loaded");
}
element.addEventListener("load", function(){
element.classList.add("loaded");
})
}
}
// Create an image element to check when it's loaded
var img = new Image();
img.src = lazyImage.src;
img.onload = function () {
lazyImage.style.opacity = 1;
};
});
};