Auto-adjust content while scrolling down

I am creating a blog on django / webfaction. Currently my hompage displays 4 messages by default (messages are limited to 4 on queryset in urls.py ). Now I would like to download four more messages after the user reaches the bottom of the page and continues until the last post is reached. How to achieve this?

+4
source share
4 answers

If you want to upload your content when you reach the lowest level of the document, use the following code:

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

If you want to download content before using up to 100 low-level pixels

 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 } }); 
+14
source

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; } }); 
+2
source

You can make an Ajax call to receive additional messages in the element's 'onscroll' event (possibly in the body in your case). You can make the same call using jquery '.scroll ()' registered here: http://api.jquery.com/scroll/

Perhaps you can support the operator of the previous top level to determine the direction of the current scroll.

+1
source

yo want something like this http://www.developphp.com/view.php?tid=1265 "

I'm sure:)

+1
source

Source: https://habr.com/ru/post/1439871/


All Articles