Home > Article > Web Front-end > JavaScript simply implements the function of returning to the top of the web page_javascript skills
Many web pages will place a "return to top" button at the bottom, especially web pages without navigation at the bottom of the page. This can help visitors find the navigation again or review the advertisement (what a beautiful idea). As JavaScript has become more and more widely used in recent years, sliding effects are everywhere, so I followed suit and made the return to top function a sliding effect. Later, in order to better fit the physical characteristics, it was modified to have a decelerating sliding effect.
First let’s talk about the principle. We will get the distance from the scroll bar to the top of the page, and then move it up a certain distance; then get the distance from the scroll bar to the top of the page, and move it up a certain distance (a little smaller than the last time); And so on...