fix: lazy load portraits

This commit is contained in:
max_richter 2023-11-20 16:57:04 +01:00
parent df3afc90a7
commit 871c6d6959

View File

@ -1,19 +1,16 @@
window.onload = function () { window.onload = function () {
// Get all <img> elements with loading="lazy" // 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 console.log(lazyImages)
lazyImages.forEach(function (lazyImage) {
lazyImage.style.opacity = 0;
lazyImage.classList.add("lazy-image")
console.log(lazyImage)
// Create an image element to check when it's loaded // Loop through each image and apply the fade-in effect
var img = new Image(); lazyImages.forEach(function (lazyImage) {
img.src = lazyImage.src; console.log(lazyImage)
img.onload = function () { var img = new Image();
console.log("lloooaded") img.src = lazyImage.src;
lazyImage.style.opacity = 1; img.onload = function () {
}; lazyImage.style.opacity = 1;
}); };
}; });
};