1. Add a tag to the page (HTML) <body></body> (back to top hyperlink)
<a href= "#0" class= "Cd-top" >Top</a>
2, add CSS style (can be written in the page, can also be written in a separate CSS style table)
. cd-top { display:inline-block; height:40px; width:40px; position:fixed; bottom:40px; right:10px; box-shadow:0 0 10px rgba (0, 0, 0, 0.05); /* Image Replacement Properties */ Overflow:hidden; text-indent:100%; White-space:nowrap; Background:rgba (232, 98, 0.8) URL (.. /IMAGES/CD-TOP-ARROW.SVG) no-repeat Center 50%; Visibility:hidden; opacity:0; -webkit-transition:all 0.3s; -moz-transition:all 0.3s; Transition:all 0.3s;}. cd-top.cd-is-visible {/ * the button becomes visible */ visibility:visible; Opacity:1;}. cd-top.cd-fade-out { /* If the user continues to scroll down, the transparency of this button becomes lower * /opacity:. 5;}. No-touch. cd-top:hover { background-color: #e86256; Opacity:1;} @media only screen and (min-width:768px) { . cd-top { right:20px; bottom:20px;} } @media only screen and (min-width:1024px) { . cd-top { height:60px; width:60px; right:30px; bottom:30px;} }
3, add JS code (before adding JS, must first refer to the jquery library, otherwise it will expire)
<script type= "Text/javascript" src= "http://apps.bdimg.com/libs/jquery/ 2.1.4/jquery.min.js "></SCRIPT>
$ (document). Ready (function ($) {//browser window scroll (in pixels) after which The "Back to Top" link was shownvar offset = 300,//browser window scroll (in pixels) after which the ' back to top ' link OPA City was reducedoffset_opacity = 1200,//duration of the top scrolling animation (in ms) Scroll_top_duration = 700,//grab the "Back to top" Link$back_to_top = $ ('. Cd-top '),//hide or show the "Back to Top" link$ (Windows). Scroll (function () {($ (this). ScrollTop () > Offset)? $back _to_top.addclass (' cd-is-visible '): $back _to_top.removeclass (' cd-is-visible cd-fade-out '); ScrollTop () > Offset_opacity) {$back _to_top.addclass (' cd-fade-out ');}}); /www.sucaijiayuan.com//smooth Scroll to Top$back_to_top.on (' click ', Function (event) {Event.preventdefault (); $ (' Body , HTML '). Animate ({scrolltop:0,}, Scroll_top_duration);});