Scroll to the top of the page using JavaScript?

后端 未结 30 1050
借酒劲吻你
借酒劲吻你 2020-11-22 03:18

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 scroll

30条回答
  •  抹茶落季
    2020-11-22 03:49

    You dont need JQuery. Simply you can call the script

    window.location = '#'
    

    on click of the "Go to top" button

    Sample demo:

    output.jsbin.com/fakumo#

    PS: Don't use this approach, when you are using modern libraries like angularjs. That might broke the URL hashbang.

提交回复
热议问题