To add a CSS:
<style>.up{width:54px;height:54px;background:url (/images/topback.gif) no-repeat 0 0;filter:alpha (Opacity=60 );-moz-opacity:0.6;opacity:0.6;}. Up:hover{filter:alpha (opacity=100);-moz-opacity:1;opacity:1;} </style>
JS Code:
var scrolltotop={setting:{startline:100,//Start line scrollto:0,//scroll to the specified position scrollduration:400,//scrolling transition time fadeduration:[ 500,100]//Fade out fades},controlhtml: ' <div class= ' up ' ></div> ',//Return top button controlattrs:{offsetx:30,offsety:80} ,//Return button fixed position anchorkeyword: "#top", State:{isvisible:false,shouldvisible:false},scrollup:function () {if (! This.cssfixedsupport) {this. $control. css ({opacity:0});} var Dest=isnan (This.setting.scrollto) this.setting.scrollto:parseInt (This.setting.scrollto); if (typeof dest== " String "&&jquery (" # "+dest). Length==1) {dest=jquery (" # "+dest). Offset (). Top;} else{dest=0;} this. $body. Animate ({scrolltop:dest},this.setting.scrollduration);},keepfixed:function () {var $window =jquery ( window) var controlx= $window. ScrollLeft () + $window. Width ()-this $control. Width ()-this.controlattrs.offsetx;var Controly= $window. scrolltop () + $window. Height ()-this. $control. Height ()-this.controlattrs.offsety;this.$ Control.css ({left:controlx+ "px", top:controly+ "px"}),},togglecontrol:function () {var scrolltop=jquery (winDow). scrolltop (); if (!this.cssfixedsupport) {this.keepfixed ();} This.state.shouldvisible= (Scrolltop>=this.setting.startline) true:false;if (this.state.shouldvisible& &!this.state.isvisible) {this. $control. Stop (). Animate ({opacity:1},this.setting.fadeduration[0]); This.state.isvisible=true;} Else{if (this.state.shouldvisible==false&&this.state.isvisible) {this. $control. Stop (). Animate ({opacity:0 },THIS.SETTING.FADEDURATION[1]); This.state.isvisible=false;}}},init:function () {jQuery (document). Ready (function ($) {var Mainobj=scrolltotop;var iebrws=document.all;mainobj.cssfixedsupport=!iebrws| | iebrws&&document.compatmode== "Css1compat" &&window. Xmlhttprequest;mainobj. $body = (window.opera)? (document.compatmode== "Css1compat"? $ ("HTML"): $ ("Body")): $ ("html,body"); mainobj. $control =$ (' <div id= ') Topcontrol "> +mainobj.controlhtml+" </div> "). css ({position:mainobj.cssfixedsupport?") Fixed ":" Absolute ", bottom:mainobj.controlattrs.offsety,right:mainobj.controlattrs.offsetx,opacity: 0,cursor: "Pointer"}). attr ({title: "Return to Top"}). Click (function () {mainobj.scrollup (); return false;}). AppendTo ("body"); if (Document.all&&!window. Xmlhttprequest&&mainobj. $control. Text ()! = "") {mainobj. $control. css ({width:mainobj. $control. Width ()});} Mainobj.togglecontrol (); $ (' a[href= "' +mainobj.anchorkeyword+ '"] '). Click (function () {mainobj.scrollup (); return false;}); $ (window). bind ("Scroll resize", function (e) {Mainobj.togglecontrol ();});});}; Scrolltotop.init ();
Note: You need to reference jquery
PC Back top Floating button