美文网首页
懒加载(记住3个高度)

懒加载(记住3个高度)

作者: 李永州的FE | 来源:发表于2017-08-08 14:57 被阅读0次

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个高度)

      本文链接:https://www.haomeiwen.com/subject/cvxyfxtx.html