jquery 动画滚动顶部回调
我有以下 jquery 将页面滚动到顶部,然后执行回调函数。
问题是,即使页面已经位于顶部,它仍然会等待“1000”过去后再执行回调,这是我不希望的。
$('html').animate({scrollTop:0}, 1000, 'swing', function(){
//do something
});
I have the following jquery that scrolls the page to the top, then performs a callback function.
The problem is that even if the page is already at the top, it still waits for the '1000' to elapse before performing the callback, which i dont want it to.
$('html').animate({scrollTop:0}, 1000, 'swing', function(){
//do something
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它不会等待,
它会从上到下为您的文档添加动画...很有趣,但事实就是这样。你还有其他选择。要么:
我的
.scrollintoview()
jQuery 插件 就是这样工作的。它仅在必要时才滚动,并在滚动完成后运行完整的处理程序(如果首先有滚动),或者如果不需要滚动则立即运行。但它需要一些需要滚动的元素。实际上,您并没有将任何元素滚动到视图中,而只是将 HTML 滚动到视图中。这当然不是最安全的方法。最好使用:
或
它更支持跨浏览器。因此,您的
$("html")
可能不适用于所有这些。It doesn't wait
It animates your document from top to the top... Funny but that's how it is. You have other alternatives. Either:
My
.scrollintoview()
jQuery plugin works that way. It scrolls only if it has to and runs a complete handler after scrolling is complete (if there was scrolling in the first place) or immediately if scrolling is not needed.But it needs some element that needs to be scrolled. You're actually not scrolling any element into view but rather just HTML. This is of course not the safest way. It's better to use either:
or
It's more cross browser supported. So your
$("html")
may not work in all of them.