12

const imgs = document.getElementsByTagName('img');
const viewHeight = window.innherHeight || document.documentElement.clientHeight;

let num = 0;
function lazyLoad() {

for (let i = num; i <= imgs.length; i++) {
    let distance = viewHeight - imgs[i].getBoundingClientRect().top;
    
    if (distance >= 0) {
        imgs[i].src = imgs[i].getAttritube('data-src')
        
        num = i + 1;
    }
}

};

window.addEventListener('scroll', lazyLoad, false);


你也很棒哦
199 声望12 粉丝

bug