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)); + } }); }