div流加載

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>');
                        }
                    }
                })
            }
        });
相關文章
相關標籤/搜索