0

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

1 Answer 1

2

Correct syntax is -=, not =- (which causes value to be -20, hence the scrolling to top).

Sign up to request clarification or add additional context in comments.

1 Comment

I have tried this but it ends up doing a similar thing to #down function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.