14

I want to put to the top bottom of the page which should scroll the page to the top. However I want the scrolling process to have animated effect. I think it is possible by using animate but have no idea how to ?

Please help. Thanks

Mukul Kant
  • 7,074
  • 5
  • 38
  • 53
Narendra Bista
  • 279
  • 1
  • 2
  • 6

2 Answers2

46

The way is pretty simple. Put a button at the bottom of the page and write an event something like this

$('#spnTop').on("click",function() {
    $('html, body').animate({ scrollTop: 0 }, 'slow', function () {
        alert("reached top");
    });
});

Here is the fiddle for this

Paras
  • 2,997
  • 6
  • 35
  • 46
7

You can animate the scrollTop property of the html, body

$('html, body').animate({
    scrollTop: "0px"
}, 800);

I suggest you do some research/reading before you ask trivial questions like these. Google can help you out before all of us can.

painotpi
  • 6,894
  • 1
  • 37
  • 70
  • 11
    And Google often points to Stack Overflow for the answer. All questions/answers, trivial or not, belong here. – Doug S May 07 '16 at 03:55