From df8ff546ec1c8d21a3d25e0124665001fcf756f3 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Mon, 26 Jun 2023 23:59:59 +0800 Subject: [PATCH] fix: the cached image is covered by shimmer (#1100) --- _javascript/modules/components/img-lazyload.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/_javascript/modules/components/img-lazyload.js b/_javascript/modules/components/img-lazyload.js index b79c87c..edad9dd 100644 --- a/_javascript/modules/components/img-lazyload.js +++ b/_javascript/modules/components/img-lazyload.js @@ -2,14 +2,26 @@ * Set up image lazy-load */ +function stopShimmer($node) { + $node.parent().removeClass('shimmer'); +} + export function imgLazy() { - if ($('#core-wrapper img[data-src]') <= 0) { + const $images = $('#core-wrapper img[data-src]'); + + if ($images.length <= 0) { return; } /* Stop shimmer when image loaded */ document.addEventListener('lazyloaded', function (e) { - const $img = $(e.target); - $img.parent().removeClass('shimmer'); + stopShimmer($(e.target)); + }); + + /* Stop shimmer from cached images */ + $images.each(function () { + if ($(this).hasClass('ls-is-cached')) { + stopShimmer($(this)); + } }); }