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");
}
});
});