smooth scroll to top

前端 未结 12 1221
眼角桃花
眼角桃花 2020-12-07 22:58

I\'ve bean searching for this for a few hours now and I have no solution. I want a smooth scroll to the top of the page. I already have smooth scrolling to separate anchors

12条回答
  •  生来不讨喜
    2020-12-07 23:21

    window.scroll({top: 0, behavior: "smooth"})
    

    Just use this piece of code and it will work perfectly, You can wrap it into a method or event.

提交回复
热议问题