Back to top button css + js, back to top css

Source: Internet
Author: User

Back to top button css + js, back to top css

Effect

Html

<p id="back-to-top"><a href="#top"><span></span></a></p>

Css

P # back-to-top {position: fixed; bottom: 100px; right: 80px;} p # back-to-top a {text-align: center; text-decoration: none; color: # d1d1d1; display: block; width: 30px;/* use the transition attribute in CSS3 to add a gradient effect to the text in the jump link */-moz-transition: color1s; -webkit-transition: color1s;-o-transition: color1s;} p # back-to-top a: hover {color: #979797 ;} p # back-to-top a span {background: # d1d1d1 url (.. /images/arrow_up.png) no-repeat center; border-radius: 6px; display: block; height: 30px; width: 30px; margin-bottom: 5px; /* use the transition attribute in CSS3 to add the gradient effect to the <span> label background color */-moz-transition: background1s;-webkit-transition: background1s;-o-transition: background1s;} # back-to-top a: hover span {background: #979797 url (.. /images/arrow_up.png) no-repeat center ;}

Js

<Script type = "text/javascript"> $ (document ). ready (function () {// first hide # back-to-top $ ("# back-to-top "). hide (); // when the position of the scroll bar is below 600 pixels from the top, the jump link appears, otherwise it disappears $ (function () {$ (window ). scroll (function () {if ($ (window ). scrollTop () & gt; 600) {$ ("# back-to-top "). fadeIn (500);} else {$ ("# back-to-top "). fadeOut (500) ;}}); // when you click the jump link, return to the top position of the page $ ("# back-to-top "). click (function () {$ ('body, html '). animate ({scrollTop: 0}, 500); return false ;}); </script>

 

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.