js--进入可视区后图片的加载

(1)利用原生的js进行判断:

window.onscroll=function(){
        var seeHeight = document.documentElement.clientHeight;
        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        for(var i=l;i<imgNum;i++){
            if(imgObj[i].offsetTop < seeHeight + scrollTop){
                if(imgObj[i].src == ""){
                    imgObj[i].src = imgObj[i].getAttribute("lazysrc");
                }
            }
            if(imgObj[i].offsetTop > seeHeight + scrollTop){
                l=i;
                break;
            }
        }
}

(2)利用jquery进行判断:

$(window).bind("scroll", function(event){
     
      $("div").each(function(){
         
           var fold = $(window).height() + $(window).scrollTop();
          
           if( fold <= $(this).offset().top){
              
                 $(this).trigger("appear");
       }
      });
 });

进入可视区后加载物体或者滚动加载图片

 

 

posted @ 2013-01-06 14:20  GM_Lv  阅读(1645)  评论(0编辑  收藏  举报