简体   繁体   English

jQuery scrollTop在移动设备上不起作用(一遍又一遍)

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

I have the following code that I am using to scroll to the top of the page. 我有以下代码用于滚动到页面顶部。 It works great, except on my android phone. 除了在我的android手机上,它的效果很好。 When "a" is clicked (on android browser) the page scrolls to the top as expected, but whenever I try to scroll back down the page, the animation starts up again even though the event does not appear to be triggered again and the page scrolls up to the top. 单击“ a”(在android浏览器上)时,页面将按预期滚动到顶部,但是每当我尝试向下滚动页面时,即使事件似乎没有再次触发并且该页面也将重新启动动画向上滚动到顶部。

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

Anyone know why the animation happens again and how I can stop it? 任何人都知道为什么动画再次发生以及如何停止动画?

I'm silly, Apparently I was calling the animate() somewhere else in my code. 我很傻,显然我在代码中的其他地方调用了animate()。 :( :(

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM