Auto load content on scroll down

雨燕双飞 提交于 2019-12-03 07:35:07
Anoop

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
    }
});

You can try something like this..

var processScroll = true;
$(window).scroll(function() {
    if (processScroll  && $(window).scrollTop() > $(document).height() - $(window).height() - 100) {
        processScroll = false;
        // your functionality here
        processScroll = true;
    }
});

You can make Ajax call to fetch more posts on 'onscroll' event of element (possibly on body in your case). You can make the same call using jquery's '.scroll()' documented here: http://api.jquery.com/scroll/

You can probably maintain a previous-top statement to determine direction of current scroll.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!