Fix lazyLoading script

This commit is contained in:
Michał Gdula 2023-04-04 14:21:16 +00:00
parent a83930e377
commit bf8142623e
5 changed files with 6 additions and 8 deletions

View file

@ -5,14 +5,12 @@ function imgFade(obj, time = 250) {
}
// Lazy load images when they are in view
function loadOnView() {
let lazyLoad = document.querySelectorAll('#lazy-load');
const lazyLoad = document.querySelectorAll('#lazy-load');
for (let i = 0; i < lazyLoad.length; i++) {
let image = lazyLoad[i];
if (image.getBoundingClientRect().top < window.innerHeight && image.getBoundingClientRect().bottom > 0) {
if (!image.src) {
image.src = `/api/file/${image.getAttribute('data-src')}?r=thumb` // e=webp
}
if (!image.src) { image.src = image.getAttribute('data-src') }
}
}
}