Ad

JQuery - How To Use Smart Way To Load Content On Scroll Top

- 1 answer

I am using this way to load old content from messages when user scrolls top.

$("#Default3").scroll(function() { 

if($("#Default3").scrollTop()<1) {

// load 10 more old data to div

});
});

However, if you scroll to top, it just loads for one time. You need to scroll a little bottom and then scroll top to load 10 more again. So I checked the facebook messaging, and noticed that they load more old content if the scroll is upper than 50% of the height. What is the correct way for doing that ?

Ad

Answer

You can scroll down one pixel, so the user would be able to scroll up again:

$("#Default3").scroll(function() { 
  if ($("#Default3").scrollTop() < 1) {
    // load 10 more old data to div
    $("#Default3").scrollTop(1);
  }
});
Ad
source: stackoverflow.com
Ad