From a8cf13157b17e178fd7386f184e5de92ac4efd20 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 20 Nov 2023 17:13:17 +0100 Subject: [PATCH] fix: lazy loading --- static/lazy.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/static/lazy.js b/static/lazy.js index 869378d..1fc11e8 100644 --- a/static/lazy.js +++ b/static/lazy.js @@ -1,16 +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"]'); - console.log(lazyImages) + console.log(lazyImages) - // 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; - }; - }); - }; + // Loop through each image and apply the fade-in effect + lazyImages.forEach(function (lazyImage) { + lazyImage.classList.add('lazy-image'); + var img = new Image(); + img.src = lazyImage.src; + img.onload = function () { + lazyImage.style.opacity = 1; + }; + }); +};