jQuery滚动到页面顶部 [英] JQuery scroll to top of page

查看:93
本文介绍了jQuery滚动到页面顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以使用jQuery以编程方式滚动到页面顶部?我目前正在尝试使用以下代码执行此操作,但无法正常工作.我目前正在使用Firefox,

Is there a way to programmatically scroll to the top of a page with jQuery? I am currently trying to do this with the following code but it is not working. I am using Firefox currently,

$(window).scrollTop($(document).height());

推荐答案

尝试一下:

$('html, body').animate({scrollTop: '0px'}, 300);

您可以立即使用0而不是300进行此操作,但这会带来快速的自动滚动效果.

You can do this with 0 instead of 300 to be instant, but this gives a quick auto-scroll effect.

这篇关于jQuery滚动到页面顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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