Skip to content

Commit

Permalink
fix: the cached image is covered by shimmer (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
cotes2020 committed Jun 26, 2023
1 parent c075e11 commit df8ff54
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions _javascript/modules/components/img-lazyload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
});
}

0 comments on commit df8ff54

Please sign in to comment.