喵-见缝插针 2009-07-17 17:59 采纳率: 0%
浏览 552
已采纳

使用 javascript / jquery 滚动到页面顶部?

I've a <button> on the page, when this button is pressed a hidden <div> is shown using 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.

转载于:https://stackoverflow.com/questions/1144805/scroll-to-the-top-of-the-page-using-javascript-jquery

  • 写回答

30条回答 默认 最新

  • local-host 2009-07-17 18:42
    关注

    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);
    

    Parameters

    • x-coord is the pixel along the horizontal axis.
    • y-coord is the pixel along the vertical axis.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(29条)

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏