Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(function() {
- function scroll(direction) {
- var scroll, i,
- positions = [],
- here = $(window).scrollTop(),
- collection = $('.message_box');
- collection.each(function() {
- positions.push(parseInt($(this).offset()['top'],0));
- });
- for(i = 0; i < positions.length; i++) {
- if (direction == 'next' && positions[i] > here) { scroll = collection.get(i); break; }
- if (direction == 'prev' && i > 0 && positions[i] >= here) { scroll = collection.get(i); break; }
- }
- if (scroll) {
- $('html, body').animate({"scrollTop": $(scroll).offset().top-50});
- $(scroll).css('color', 'blue');
- $(scroll).mouseleave(function() {
- $(this).css('color', 'black');
- });
- }
- return false;
- }
- $("#next,#prev").click(function() {
- return scroll($(this).attr('id'));
- });
- $('body').keyup(function(event) {
- if (event.which == 74) {
- return scroll('next');
- }
- });
- $('body').keyup(function(event) {
- if (event.which == 75) {
- return scroll('prev');
- }
- });
- });
- $('html, body').animate({"scrollTop": $(scroll).offset().top-50});
- if (direction == 'next' && positions[i] > here + 50) {
- scroll = collection.get(i);
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement