页脚出现时无限滚动问题

时间:2015-05-26 12:45:59

标签: php ajax

当滚动条到达页脚而不是文档的末尾时,我需要无限滚动。我用这种方式使用了代码片段

$(window).scroll(function(){
    if($(window).scrollTop()==$(document).height()-$(window).height())
    {
        load++;
        if(load*ippage>nbr)
        {
            $(".loader").hide();    
        }
        else
        {               
            $.ajax({
                url: "fetch_array.php",
                type: "POST",
                data:{"load":load,"item_per_page":ippage,"typeno":category},
                dataType: "html",
                success: function(result)
                {
                    var results = $.parseJSON(result);
                    var dataCount=results["displayCount"]+8;
                    if(results["displayCount"]!=0)
                    {
                        scrollDisplayContent(category,results['productResults'],dataCount);
                    }
                    else
                    {
                    }
                }
            });
        }
    }

});

为了达到页脚,我只是尝试了这种方式

var footer=$(footer).height();
$(window).scroll(function(){
    if($(window).scrollTop()==($(document).height()-$(window).height()-footer))
    {
        load++;
        if(load*ippage>nbr)
        {
            $(".loader").hide();    
        }
        else
        {               
            $.ajax({
                url: "fetch_array.php",
                type: "POST",
                data:{"load":load,"item_per_page":ippage,"typeno":category},
                dataType: "html",
                success: function(result)
                {
                    var results = $.parseJSON(result);
                    var dataCount=results["displayCount"]+8;
                    if(results["displayCount"]!=0)
                    {
                        scrollDisplayContent(category,results['productResults'],dataCount);
                    }
                    else
                    {
                    }
                }
            });
        }
    }
});

但它不能正常工作任何人都可以帮助我这个

1 个答案:

答案 0 :(得分:1)

您好Deepak尝试这有助于您的查询。

screen_size=$(document).height();

var footer=$(footer).height();

scroll_limit=parseInt(screen_size)-footer;


$(document).on("scroll",function(){

  cur_size=$(document).scrollTop();

  if(parseInt(cur_size) > parseInt(scroll_limit)){
     console.log(3);
    //put here your ajax function
  }
  else{
       console.log(1);
  }

});