Posted By

tomdowning on 09/21/11


Tagged

jqueryajax


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

jillella
spee66


JQuery ajax blog loader


 / Published in: jQuery
 

scroll to bottom of browser and load in next set of posts

  1. //lazyload
  2.  
  3. var page = 1;
  4. var loading = false;
  5. minus = 40;
  6. if((navigator.userAgent.match(/iPhone/i))) minus = 240;
  7.  
  8. $(window).scroll(function() {
  9. if($(window).scrollTop() >= $(document).height() - $(window).height() - minus){
  10. page ++;
  11. nextPage();
  12. }
  13. });
  14.  
  15. function nextPage() {
  16. if(loading) return;
  17. $('#postHolder').append('<div id="blog_preloader"></div>');
  18. loading = true;
  19.  
  20. jQuery.ajax({
  21. type: "GET",
  22. data: 'page=' + page,
  23. url: "/ajax-file.php",
  24. success: function(results) {
  25. $(results).appendTo('#postHolder');
  26. $('#blog_preloader').remove();
  27. loading = false;
  28. }
  29. });
  30. }

Report this snippet  

You need to login to post a comment.