<img class="main-header-bottom-top-img" src="默认的图片在这里插入代码片"
data-src="加载的图片"/>
var clock;
clock = setTimeout(function () {
start()
}, 200)
$(window).on('scroll', function () {
if (clock) {
clearTimeout(clock);
}
clock = setTimeout(function () {
start()
}, 200)
})
function start () {
$('img').not('[data-isLoading]').each(function () {
if (isShow($(this))) {
loadImg($(this));
}
})
}
function isShow ($node) {
return $node.offset().top <= $(window).height() + $(window).scrollTop();
}
function loadImg ($img) {
$img.attr('src', $img.attr('data-src'));
$img.attr('data-isLoading', 1);
}