Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. $(function() {
  2. function scroll(direction) {
  3.  
  4. var scroll, i,
  5. positions = [],
  6. here = $(window).scrollTop(),
  7. collection = $('.message_box');
  8.  
  9. collection.each(function() {
  10. positions.push(parseInt($(this).offset()['top'],0));
  11. });
  12.  
  13. for(i = 0; i < positions.length; i++) {
  14. if (direction == 'next' && positions[i] > here) { scroll = collection.get(i); break; }
  15. if (direction == 'prev' && i > 0 && positions[i] >= here) { scroll = collection.get(i); break; }
  16. }
  17.  
  18. if (scroll) {
  19. $('html, body').animate({"scrollTop": $(scroll).offset().top-50});
  20. $(scroll).css('color', 'blue');
  21. $(scroll).mouseleave(function() {
  22. $(this).css('color', 'black');
  23. });
  24. }
  25.  
  26. return false;
  27. }
  28.  
  29. $("#next,#prev").click(function() {
  30. return scroll($(this).attr('id'));
  31. });
  32. $('body').keyup(function(event) {
  33. if (event.which == 74) {
  34. return scroll('next');
  35. }
  36. });
  37. $('body').keyup(function(event) {
  38. if (event.which == 75) {
  39. return scroll('prev');
  40. }
  41. });
  42.  
  43. });
  44.  
  45. $('html, body').animate({"scrollTop": $(scroll).offset().top-50});
  46.  
  47. if (direction == 'next' && positions[i] > here + 50) {
  48. scroll = collection.get(i);
  49. break;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement