Scroll to the top of the page using JavaScript?

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

    All of these suggestions work great for various situations. For those who find this page through a search, one can also give this a try. JQuery, no plug-in, scroll to element.

    $('html, body').animate({
        scrollTop: $("#elementID").offset().top
    }, 2000);
    

提交回复
热议问题