Auto-pager scroll


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /* Ajax pages */
  2.  
  3. if ($("span.curr_page").length) {
  4. $("#loader").show();
  5. }
  6. pulling = false;
  7.  
  8. function grabPage(next_page) {
  9. if (next_page && pulling == false) {
  10. pulling = true;
  11. $.get(next_page,
  12.  
  13. function(data) {
  14. var pages = data.split("<!--PAGES-->");
  15. var new_pages = pages[1];
  16.  
  17. var posts = data.split("<!--POSTS-->");
  18. var new_posts = posts[1];
  19. $("div.post:last").after(new_posts);
  20. $("div#pagination").html(new_pages);
  21. pulling = false;
  22. });
  23. }
  24. }
  25.  
  26. $(window).scroll(function() {
  27. var currpos = 0.8*($(document).height() - $(window).height());
  28.  
  29. if ($("span.curr_page").length && $("#older").length) {
  30. if ($(window).scrollTop() > currpos) {
  31. grabPage($("#older").attr("href"));
  32. }
  33. } else {
  34. $("#loader").hide();
  35. }
  36. });

URL: http://pastie.org/608232

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.