Guest User

Untitled

a guest
Feb 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.06 KB | None | 0 0
  1. $(document).ready(function(){
  2.    
  3.     $(function() {
  4.  
  5.     function scroll(direction) {
  6.  
  7.         var scroll, i,
  8.                 positions = [],
  9.                 here = $(window).scrollTop(),
  10.                 collection = $('li.post');
  11.  
  12.         collection.each(function() {
  13.             positions.push(parseInt($(this).offset()['top'],10));
  14.         });
  15.  
  16.         for(i = 0; i < positions.length; i++) {
  17.             if (direction == 'next' && positions[i] > here) { scroll = collection.get(i); break; }
  18.             if (direction == 'prev' && i > 0 && positions[i] >= here) { scroll = collection.get(i-1); break; }
  19.         }
  20.  
  21.         if (scroll) {
  22.             $.scrollTo(scroll, {
  23.                 duration: 750      
  24.             });
  25.         }
  26.  
  27.         return false;
  28.     }
  29.  
  30.     $("#next, #prev").click(function() {        
  31.         return scroll($(this).attr('id'));        
  32.     });
  33.  
  34.    
  35. $(document).keyUp(function(e){ if (e.keyCode == 40) $('#prev').trigger('click'); });
  36. $(document).keyUp(function(e){ if (e.keyCode == 38) $('#next').trigger('click'); });
  37.  
  38. });
Add Comment
Please, Sign In to add comment