Saber2pr's Blog

ReturnToTheTopOfThePage

Positioning using Anchor Point

Below the body is a hidden anchor tag:

<a id="top"></a>

Put an access link at the bottom of the page:

<a href="#top">返回顶部</a>

Click `return to the top 'page to navigate to the a#top location.

ScrollTop

document.documentElement.scrollTop = 0

ScrollTo

scrollTo(0, 0)

ScrollBy

window.scrollBy({ top: -document.documentElement.scrollTop })

Options parameter Smooth scrolling

window.scrollBy({
  top: -document.documentElement.scrollTop,
  behavior: "smooth"
})