jQuery scrollTop 不能在 Chrome 中工作,但可以在 Firefox 中工作 [英] jQuery scrollTop not working in Chrome but working in Firefox

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

问题描述

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

但它在 Firefox 中仍然可以顺利运行.可能有什么问题?

这是我使用的jQuery函数,

jQuery:

$('a#gotop').click(function() {$("html").animate({ scrollTop: 0 }, "slow");//alert('动画完成.');//返回假;});

HTML

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

CSS

#gotop {光标:指针;位置:相对;浮动:对;右:20px;/*顶部:0像素;*/}

解决方案

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

这在 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.

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

解决方案

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

This works for me in chrome.

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

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