var _timer = {}; function delay_till_last(id, fn, wait) { if (_timer[id]) { window.clearTimeout(_timer[id]); delete _timer[id]; } return _timer[id] = window.setTimeout(function() { fn(); delete _timer[id]; }, wait); } $(document).ready(function() { var Ajax_Url = null; $(window).scroll(function(){ delay_till_last(‘scroll_Ajax‘, function(){ if($(window).scrollTop() >= $(document).height() - $(window).height() - 80){ //如果你没有底部固定栏可以把 80 适当减少 Ajax_Url = $(".nextpage a").attr("href");//一个隐藏 a 标签储存下一页要拉取的链接 if( Ajax_Url ){ $.ajax({ type: "GET", url: Ajax_Url, success: function(data){ $(".nextpage").remove(); $(".postlist").append(data); }, error: function(data){ $(".postlist").after(‘<div id="ajax-list-error">文章获取失败</div>‘); } }); }else{ ajax_load_hide(); $("#ajax-list-error").remove(); $(".postlist").after(‘<div id="ajax-list-error">全部文章已加载完毕,没有更多的文章了~</div>‘); } } }, 100); }); });
|