function isVisible(e) {
const position = e.getBoundingClientRect();
const windowHeight = document.docuemtnElement.clientHeight;
const topVisible = position.top > 0 && position.top < windowHeight;
const bottomVisible = position.bottom < windowHeight && position.bottom > 0;
return topVisibile || bottomVisible;
}
function imageLazyLoad() {
const images = document.querySelectorAll('img');
for (let img of images) {
const realSrc = img.dataset.src;
if (!realSrc) continue;
if (isVisible(img)) {
img.src = realSrc;
img.dataset.src = '';
}
}
}