1

I have a scroll back to top button that brings the user back to the top of the page with a smooth glide. It is working in Firefox but not Chrome:

$('a#scroll-to-top').click(function() {
    $('html').animate({
        scrollTop: 0
    }, 500);
    return false;
});

<a href="#" id="scroll-to-top">Up Top</a>

How to get this to work in Chrome?

  • possible duplicate of [How do I scroll to the top of the page with jQuery?](http://stackoverflow.com/questions/1144805/how-do-i-scroll-to-the-top-of-the-page-with-jquery) – j08691 May 14 '12 at 22:39
  • @j08691 not quite the same question – CharlesB May 18 '12 at 08:23

2 Answers2

4

You would like to use this code:

$('a#scroll-to-top').click(function() {
    $('html, body').animate({
        scrollTop: 0
    }, 500);
    return false;
});

​Here is example

1

Just use body instead of html like below:

$('a#scroll-to-top').click(function() {
  $('body').animate({
    scrollTop: 0
 }, 500);
  return false;
});