Very many sites have the effect of returning to the top , this article explains how to use the jquery implementation to return to the top button.
First, you need to add the following HTML elements at the top:
<p id= "Back-to-top" ><a href= "#top" ><span></span> back to top </a></p>
The a tag, which points to the top of the anchor point, prevents one anchor point from being in front of it <a name="top"></a>
, so that the top effect can be achieved when the browser does not support JS.
To make the top picture appear on the right side. Some CSS styles are also required. For example, the following:
/*returntop*/p#back-to-top{position:fixed; Display:none; bottom:100px; right:80px;} P#back-to-top a{Text-align:center; Text-decoration:none; Color: #d1d1d1; Display:block; width:64px; /* Add a gradient effect to the text in the Jump link using the transition attribute in CSS3 */-moz-transition:color 1s; -webkit-transition:color 1s; -o-transition:color 1s;} P#back-to-top a:hover{color: #979797;} P#back-to-top a span{background:transparent url (/static/imgs/sprite.png?1202) no-repeat-25px-290px; border-radius:6px; Display:block; height:64px; width:56px; margin-bottom:5px; /* Use the transition attribute in CSS3 to add a gradient effect to the <span> label background color */-moz-transition:background 1s; -webkit-transition:background 1s; -o-transition:background 1s;} #back-to-top a:hover span{background:transparent url (/static/imgs/sprite.png?1202) no-repeat-25px-290px;}
The background picture in the above style is sprite. The following provides two separate top pictures for friends to use:
With HTML and styling, we also need to use the JS control to return to the top button and fade out to the top button as the page scrolls.
<script src=" Http://ajax.microsoft.com/ajax/jQuery/jquery-1.7.2.min.js "></script ><script>$ (function () {////When the position of the scroll bar is below 100 pixels from the top, the jump link appears. Otherwise disappears $ (function () {$ (window). Scroll (function () {if (window). scrolltop () >100) { $ ("#back-to-top"). FadeIn (1500); } else {$ ("#back-to-top"). FadeOut (1500); } }); When you click the Jump link, go back to the top of the page at $ ("#back-to-top"). Click (function () {$ (' body,html '). Animate ({scrolltop:0},100 0); return false; }); }); }); </script>
So that's it.
Note that loading the page requires a little bit of scrolling after dragging the top of the talent to see enough.
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
Use the jquery popular feature to implement