- HTML structure
-
<Divclass= "Toolbar" > <ahref= "javascript:;"class= "Toolbar-item"> <spanclass= "Toolbar-btn"ID= "Backtop"> <Iclass= "Toolbar-icon icon-upload2"></I>//Icon font <spanclass= "Toolbar-text">Return<BR/>Top of</span> </span> </a></Div>
- CSS Styles
-
. Toolbar{position:fixed; Right:10px;Bottom:20px;}. Toolbar-item{position:relative;Display:Block;width:50px;Height:50px;&:hover{. toolbar-icon{top: [email protected]; }. Toolbar-text{Top:0; }}}.toolbar-btn{position:Absolute; Left:0;Top:0;width:50px;Height:50px;Overflow:Hidden;. toolbar-icon{position:Absolute; Left:0;Top:0;width:50px;Height:50px;Background-color:#ccc;font-size:30px;Color:#fff;text-align:Center;transition:top 1s; }. Toolbar-text{position:Absolute; Left:0;Top:50px;width:50px;Height:50px;Background-color:#A0A0A0;font-size:14px;Color:#fff;text-align:Center;transition:top 1s; }}
- jquery implementation returns to top
-
<script type= "Text/javascript" > $(function() { $(' #backtop '). On (' click ', move); $ (window). On (' Scroll ',function() {checkposition (window). Height ()); }); functionMove () {$ (' Html,body '). Animate ({scrolltop:0 },800); } functioncheckposition (H) {if($ (window). scrolltop () >H) { $(' #backtop '). FadeIn (); } Else{ $(' #backtop '). FadeOut (); } } })</script>
At this point, return to the top button function basic implementation
jquery implementation returns top Button function