懒加载

2017-10-11  本文已影响0人  727上上上

题目一

function isVisible($node){
    if($node.offset().top<$(window).height+$(window).scrollTop()
        && $node.offset().top>$(window).scrollTop()){
            return true
        }
        return false
}

题目二

$(window).on('scroll',function(){
    if($node.offset().top<$(window).height+$(window).scrollTop()
        && $node.offset().top>$(window).scrollTop()){
            console.log(true)
        }
})

题目三

$(window).on('scroll',function(){
    if($node.offset().top<$(window).height+$(window).scrollTop()
        && $node.offset().top>$(window).scrollTop()){
            if(!$node.attr('loaded'){
                console.log(true)
                $node.addClass('loaded')
            })
        }
})

题目四

对于所有的Img标签,把真实的地址放入自定义属性里,因此平时图片不会加载
滚动页面时,检查所有img标签,是否出现在视野中,再判断是否加载过,如果没有则加载

上一篇下一篇

猜你喜欢

热点阅读