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

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

问题描述

我在页面上有一个< button> ,按下此按钮后隐藏< div> 使用jQuery显示。

I've a <button> on the page, when this button is pressed a hidden <div> is shown using jQuery.

如何在该函数中使用JavaScript / jQuery命令滚动到页面顶部?即使滚动条立即跳到顶部也是可取的。我不是在寻找平滑滚动。

How do I scroll to the top of the page using a JavaScript/jQuery command in that function? It is desirable even if the scroll bar instantly jumps to the top. I'm not looking for a 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(x-coord, y-coord);

参数


  • x-coord是沿水平轴的像素。

  • y-coord是沿垂直轴的像素。

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

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