Reputation: 4865
I have this code & when I click #down
the page scrolls down by 20, which is correct. When I click #up
the page scrolls right to the top which is wrong as I want the page scroll up by 20 only. Here's the code I'm working with:
$('#up').click(function(){
$('html, body').animate({
scrollTop: $(this).offset().top -= 20
});
return false;
});
$('#down').click(function(){
$('html, body').animate({
scrollTop: $(this).offset().top += 20
});
return false;
});
Any input would be greatly appreciated, Thanks
Upvotes: 0
Views: 157
Reputation: 19049
Correct syntax is -=, not =- (which causes value to be -20, hence the scrolling to top).
Upvotes: 2