jQuery scrollTop在Chrome中不起作用,但在Firefox中起作用 [英] jQuery scrollTop not working in Chrome but working in Firefox

查看:133
本文介绍了jQuery scrollTop在Chrome中不起作用,但在Firefox中起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用jQuery中的scrollTop函数导航到顶部,但是奇怪的是,在进行了一些更改之后,平滑动画滚动"在Safari和Chrome中停止工作(滚动时没有平滑动画).

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.

但是它在Firefox中仍然可以正常运行.有什么问题吗?

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

这是我使用的jQuery函数,

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;*/
}

推荐答案

尝试使用$("html,body").animate({ scrollTop: 0 }, "slow");

这在Chrome浏览器中对我有效.

This works for me in chrome.

这篇关于jQuery scrollTop在Chrome中不起作用,但在Firefox中起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆