懒加载(记住3个高度)

let $theImage = $('img[data-src]').first()
let 图片上边缘距离页面顶部的距离 = $theImage.offset().top

$(window).on('scroll', function (e) {
let top = window.scrollY
if (top + $(window).height() >= 图片上边缘距离页面顶部的距离) {
$theImage[0].src = $theImage[0].getAttribute('data-src')
} else {
console.log('还没到')
}
})

你可能感兴趣的:(懒加载(记住3个高度))