Javascript _ javascript tips

Source: Internet
Author: User
This article mainly introduces how to use javascript to implement the Back-to-top button and source code in the lower-right corner of the blog garden page. It is very good. It is recommended to our friends for the cool back-to-top function.

Js core code

Window. onscroll = function () {var t = document.doc umentElement. scrollTop | document. body. scrollTop; var top_p = document. getElementById ("go"); if (t> = 300) {top_p.style.display = "block";} else {top_p.style.display = "none" ;}} var ptt = 20; function pageScroll () {document. getElementById ('flypig '). style. display = 'block'; window. scrollBy (0,-10); // each time it rises by 10px if (document. body. scrollTop = 0) {document. getElementById ('flypig '). style. marginBottom = ptt + 'px'; ptt = ptt + 10;} scrolldelay = setTimeout ('pagescroll () ', 2 ); // repeat once in 2 milliseconds if (ptt> = 1000) {ptt = 0; document. getElementById ('flypig '). style. marginBottom = 20 + 'px '; document. getElementById ('flypig '). style. display = 'none'; clearTimeout (scrolldelay);} // pageScroll ends}

Html

 Return to the top button implementation 
 Script window. onscroll = function () {var t = document.doc umentElement. scrollTop | document. body. scrollTop; var top_p = document. getElementById ("go"); if (t> = 300) {top_p.style.display = "block";} else {top_p.style.display = "none" ;}} var ptt = 20; function pageScroll () {document. getElementById ('flypig '). style. display = 'block'; window. scrollBy (0,-10); // each time it rises by 10px if (document. body. scrollTop = 0) {document. getElementById ('flypig '). style. marginBottom = ptt + 'px'; ptt = ptt + 10;} scrolldelay = setTimeout ('pagescroll () ', 2 ); // repeat once in 2 milliseconds if (ptt> = 1000) {ptt = 0; document. getElementById ('flypig '). style. marginBottom = 20 + 'px '; document. getElementById ('flypig '). style. display = 'none'; clearTimeout (scrolldelay);} // pageScroll ends} script













Please go down






















































































Back to Top

The above is all the content of this article. I hope you will like it.

Related Article

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.