<img data-src='路径'/>
window.addEventListener('load', function () {
var imgs = document.querySelectorAll('img');
img = Array.from(imgs);
console.log(img);
var h = document.documentElement.clientHeight||document.body.clientHeight;
var scrollTop = 0
window.onscroll = function () {
scrollTop = document.documentElement.scrollTop||document.body.scrollTop;
// console.log(scrollTop);
for (var i = 0; i < imgs.length; i++) {
var offsetTop = imgs[i].offsetTop;
if (offsetTop < h + scrollTop) {
imgs[i].src = imgs[i].dataset.src
}
}
}
for (var i = 0; i < imgs.length; i++) {
var offsetTop = imgs[i].offsetTop;
if (offsetTop < h + scrollTop) {
imgs[i].src = imgs[i].dataset.src
}
}
})