懒加载

作者: 727上上上 | 来源:发表于2017-10-11 14:35 被阅读0次

    题目一

    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标签,是否出现在视野中,再判断是否加载过,如果没有则加载

    相关文章

      网友评论

          本文标题:懒加载

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