var hasNext=true;//触发开关,防止多次调用事件 var nScrollHight = 0; //滚动距离总长(注意不是滚动条的长度) var nScrollTop = 0; //滚动到的当前位置 var nDivHight = $('#main').height(); $('#main').scroll(function(){ nScrollHight = $(this)[0].scrollHeight; nScrollTop = $(this)[0].scrollTop; var paddingBottom = parseInt( $(this).css('padding-bottom') ),paddingTop = parseInt( $(this).css('padding-top') ); if(nScrollTop + paddingBottom + paddingTop + nDivHight + 100 >= nScrollHight && hasNext==true){ hasNext = false; $.ajax({ url:'/blog/'+page++, data:'', type:'post', dataType:'text', success:function(result){ if(result.code){ $('#article-list').append(result); hasNext = true; }else{ hasNext = false; $('#article-list').append('<div class="alert with-icon"><i class="icon-info-sign"></i><h3 class="content">'+ result.message +'</h3></div>'); } } }) } });