Advertisement
Guest User

Mobile Infinite Scroll

a guest
Jan 21st, 2011
6,106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.    
  3.     /* Bind the touchevent (if touch events exist)
  4.     -------------------------------------------------------------- */
  5.    
  6.     if (Modernizr.touch) $(document).bind('mouseup touchend', mobileInfscr);
  7.    
  8.    
  9.     /* Infinite Scroll
  10.     -------------------------------------------------------------- */
  11.  
  12.     $('#article-grid').infinitescroll({
  13.         navSelector: '#page-nav',
  14.         nextSelector: '#page-nav a',
  15.         itemSelector: 'div.article',
  16.         loadingText: 'Loading the next page',
  17.         loadingMsgRevealSpeed : 0,
  18.         animate: false,
  19.         extraScrollPx: 0,
  20.         donetext: 'No more pages to load',
  21.         bufferPx: 80,
  22.         debug: false
  23.     });
  24.    
  25.    
  26.     /* Event fired on touchevent
  27.     -------------------------------------------------------------- */
  28.  
  29.     function mobileInfscr() {
  30.        
  31.         setTimeout(function() {
  32.             var documentHeight = $(document).height();
  33.             var scrollHeight = $(window).scrollTop();
  34.             var distanceLeft = documentHeight - scrollHeight;
  35.  
  36.             if (distanceLeft < 500) {
  37.                 $(document).trigger('retrieve.infscr');
  38.             }
  39.         }, 400)
  40.        
  41.     };
  42.    
  43. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement