自己项目里的,你参考一下,需引入imgLazyLoad插件 var scrollHeight = $(document).height(); var windowHeight = $(window).height(); var scrollTop = 0; $(window).scroll(function(){ scrollTop = $(this).scrollTop(); if (scrollTop + windowHeight == scrollHeight) { if(lock){ tips('没有更多数据', 1500); return false; } lock = true ; $.ajax({ type:'get', url:'&start='+start+'&offset='+offset, data:'', success:function(a){ if(a.length > 0){ for (var i = 0; i < a.length; i++) { html += '<li data-id="' + a[i].tid + '">' + '<div class="img">' + '<img src="images/default-358-358.png" data-src="' + a[i].attachment + '">' + '</div>' + '</li>'; } $('.picture-list').append(html); //图片懒加载 $.imgLazy({viewport: true}); start += offset; html = ''; lock = false; }else{ tips('没有更多数据', 1500); } }, error:function(a){ tips('加载失败', 1500); }, dataType:'json' }); } });
自己项目里的,你参考一下,需引入imgLazyLoad插件