How to scroll up with Jquery?

javascript, jquery, scroll, scrollview

Solution

You need to supply a `0` as the argument to `scrollTop` if you want it to scroll upwards.

$(document).ready(function() {
    // scroll down
    $("html, body").animate({
        scrollTop: $(document).height()
    }, 9000);                  

    /scroll back up
    $("html, body").animate({
        scrollTop: 0
    }, 9000);                  
});

As you can see in the documentation, you need to provide a CSS property and a value as the first param to `animate()`. Since `scrollTop` (doc of `scrollTop()`, which returns the current value) is the vertical scroll bar and you want to scroll to the top, you need `0` there to go upwards.

Check this jfiddle for a demonstration.

Problem

I tried everything, and i can't write the good Jquery code to make my body scrolls up. This is my JS : `$("body").animate({scrollTop:$(document).height()}, 9000); $(this).fadeOut(fast); ` And it makes the body scroll down when user click on a specific div, then i want to reverse this function to make the body scrolls up.. any idea ?

Original source