From 871c6d695922eb1e5d24e2b58769c0be523ca6cf Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 20 Nov 2023 16:57:04 +0100 Subject: [PATCH] fix: lazy load portraits --- static/lazy.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/static/lazy.js b/static/lazy.js index bee6e3b..869378d 100644 --- a/static/lazy.js +++ b/static/lazy.js @@ -1,19 +1,16 @@ -window.onload = function () { - // Get all elements with loading="lazy" - var lazyImages = document.querySelectorAll('img[loading="lazy"]'); + window.onload = function () { + // Get all elements with 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") - console.log(lazyImage) + console.log(lazyImages) - // Create an image element to check when it's loaded - var img = new Image(); - img.src = lazyImage.src; - img.onload = function () { - console.log("lloooaded") - lazyImage.style.opacity = 1; - }; - }); -}; + // 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; + }; + }); + };