Many Web pages place a "Back to Top" button at the bottom, especially those without navigation at the bottom of the page.
Many Web pages place a "Back to Top" button at the bottom of the page, especially those without navigation at the bottom of the page, which can help visitors find the navigation again or review the advertisement (think really beautiful ). As JavaScript has become more and more widely used in recent years, and the sliding effect is everywhere, I followed suit and made the function of returning to the top into a sliding effect. Later, in order to better fit the physical characteristics, the system made the sliding effect of deceleration.
Let's talk about the principle first. We will get the distance from the scroll bar to the top of the page, move it up to a certain distance, and then get the distance from the scroll bar to the top of the page, move up a certain distance (a little smaller than the previous one); and so on...
Run the code first: