最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery animate() not working in Chrome - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question asked May 14, 2012 at 22:32 user967451user967451 2
  • possible duplicate of How do I scroll to the top of the page with jQuery? – j08691 Commented May 14, 2012 at 22:39
  • @j08691 not quite the same question – CharlesB Commented May 18, 2012 at 8:23
Add a ment  | 

2 Answers 2

Reset to default 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

Just use body instead of html like below:

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

评论列表(0)

  1. 暂无评论