PC Back top Floating button

Source: Internet
Author: User

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

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.