Scroll to the top of the page using JavaScript?

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

    
    

    Edit:

    $('html, body').animate({scrollTop:(scroll_pos)}, 2000);
    

    Another way scroll with top and left margin:

    window.scrollTo({ top: 100, left: 100, behavior: 'smooth' });
    

提交回复
热议问题