使用JavaScript滚动到页面顶部吗? [英] Scroll to the top of the page using JavaScript?

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

问题描述

如何使用JavaScript滚动到页面顶部?滚动条立即跳转到页面顶部也是可取的,因为我不想获得平滑的滚动.

How do I scroll to the top of the page using JavaScript? The scrollbar instantly jumping to the top of the page is desirable too as I'm not looking to achieve smooth scrolling.

推荐答案

如果不需要更改以进行动画处理,则无需使用任何特殊的插件-我只使用本机JavaScript window.scrollTo()方法-传入0, 0会立即将页面滚动到左上角.

If you don't need the change to animate then you don't need to use any special plugins - I'd just use the native JavaScript window.scrollTo() method -- passing in 0, 0 will scroll the page to the top left instantly.

window.scrollTo(xCoord, yCoord);

参数

  • xCoord是沿水平轴的像素.
  • yCoord是沿垂直轴的像素.

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

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