共计 367 个字符,预计需要花费 1 分钟才能阅读完成。
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].src.getAttritube(‘data-src’)
num = i + 1;
}
}
};
window.addEventListener(‘scroll’, lazyLoad, false);
正文完
发表至: javascript
2019-01-21