JavaScript simple implementation of Web Page Back to Top function _ javascript tips-js tutorial

Source: Internet
Author: User
JavaScript allows you to simply return to the top of a webpage. You can refer to the fact that many webpages place a "Back to Top" button at the bottom, especially those without navigation at the bottom of the page, this will help visitors find the navigation again or review the advertisement (really nice ). 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...

The Code is as follows:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.