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
});
retu开发者_如何转开发rn false;
});
Any input would be greatly appreciated, Thanks
Correct syntax is -=, not =- (which causes value to be -20, hence the scrolling to top).
精彩评论