jQuery scrollTop not working in Chrome but working in Firefox

Maju picture Maju · Jun 15, 2010 · Viewed 103.3k times · Source

I have used a scrollTop function in jQuery for navigating to top, but strangely 'the smooth animated scroll' stopped working in Safari and Chrome (scrolling without smooth animation) after I made some changes.

But it is still working smoothly in Firefox. What could be wrong?

Here is the jQuery function I used,

jQuery:

$('a#gotop').click(function() {
    $("html").animate({ scrollTop: 0 }, "slow");
    //alert('Animation complete.');
    //return false;
});

HTML

<a id="gotop" href="#">Go Top </a>

CSS

#gotop {
      cursor: pointer;
      position: relative;
      float: right;
      right: 20px;
      /*top:0px;*/
}

Answer

Aaron Harun picture Aaron Harun · Jun 15, 2010

Try using $("html,body").animate({ scrollTop: 0 }, "slow");

This works for me in chrome.