Return to the top of the Code implemented by JavaScript and scroll with the scroll bar

Source: Internet
Author: User

JavaScript implementation returns to the top of the code and can follow the scroll bar to scroll. This is the code shown by the Helper's house editor in Baidu space. I don't know who the original author is, the "Back to Top" button in the Code is originally an image. Because the image path is incorrect, it is replaced by a text link by a small editor. You can modify it on your own.

Demo:

<Div style = "height: 2800px;"> <script type = "text/javascript"> var w = 240; var h = 59; var str = ""; var obj = document. getElementById ("divStayTopLeft"); if (obj) str = obj. innerHTML; if (typeof document. compatMode! = 'Undefined' & document. compatMode! = 'Background') {document. writeln ('<DIV style = "z-index: 9; right: 0; bottom: 0; height:' + h + 'px; width: '+ w + 'px; overflow: hidden; POSITION: fixed; _ position: absolute; _ margin-top: expression(document.documentelement.clientheightthis.style.pixelheight#document.doc umentElement. scrollTop); "> ');} else {document. writeln ('<DIV style = "z-index: 9; right: 0; bottom: 0; height:' + h + 'px; width: '+ w + 'px; overflow: hidden; POSITION: fixed; * position: absolute; * top: expression (eval (document. body. scrollTop) + eval (document. body. clientHeight)-this. style. pixelHeight); "> ');} document. writeln ('<div style = "clear: both; margin: auto; height: 59px; font-size: 16px; overflow: hidden; font-weight: bold; text-align: left; "> <a href =" javascript: scroll (0, 0) "hidefocus =" true "> Back to Top </a> </div> '); document. write ('<div style = "clear: both; margin: auto; overflow: hidden; text-align: left;">' + str + '</div> '); document. writeln ('</DIV>'); </script> <br/> <center> If the page cannot be displayed, press Ctrl + F5 to refresh the page. For more page code: <a href =' http://www.bkjia.com/ 'Target = '_ blank'> http://www.bkjia.com/ </A> </center>

Tip: the code can be modified before running!

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.