jQuery scrollTop不工作(重复一遍又一遍)的移动

jQuery scrollTop not working (repeats over and over again) for mobile

本文关键字:一遍 移动 scrollTop 工作 jQuery      更新时间:2023-09-26

我有下面的代码,我使用滚动到页面的顶部。它非常好用,除了我的安卓手机。当点击"a"时(在android浏览器上),页面按预期滚动到顶部,但每当我尝试向下滚动页面时,动画再次启动,即使事件似乎没有再次触发,页面向上滚动到顶部。

$("a").click(function(){
    $("html, body").animate({ scrollTop: 0 }, 500);
});

谁知道为什么动画又发生了,我怎么才能停止它?

我很傻,显然我在代码的其他地方调用了animate()。(