Scroll to the top of the page using JavaScript?

后端 未结 30 1056
借酒劲吻你
借酒劲吻你 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:37

    Why don't you use JQuery inbuilt function scrollTop :

    $('html, body').scrollTop(0);//For scrolling to top
    
    $("body").scrollTop($("body")[0].scrollHeight);//For scrolling to bottom
    

    Short and simple!

提交回复
热议问题