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

I have a scroll back to top button that brings the user back to the top of the page with a smooth glide

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;
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745093968a4610861.html

相关推荐

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

    I have a scroll back to top button that brings the user back to the top of the page with a smooth glide

    16小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信