Auto load content on scroll down

前端 未结 3 868
北恋
北恋 2021-02-09 14:49

I am creating a blog on django/webfaction. My hompage currently displays 4 posts by default (posts are limited to 4 on queryset in urls.py). Now I woul

3条回答
  •  情深已故
    2021-02-09 15:28

    If you want to load your content on reaching extreme bottom of document use following code:

    $(window).scroll(function()
    {
        if($(window).scrollTop() == $(document).height() - $(window).height())
        {
              // load your content
        }
    });
    

    If you want to load content before reaching 100 pixel of bottom use

    var loading= false;
    $(window).scroll(function() {
        if (!loading && ($(window).scrollTop() >  $(document).height() - $(window).height() - 100)) {
            loading= true;
    
            // your content loading call goes here.
    
            loading = false; // reset value of loading once content loaded
        }
    });
    

提交回复
热议问题