开发者

Scroll function not working properly, using JQuery?

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜