<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<script type= "Text/javascript" src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></ Script> <script type= "Text/javascript" src= "Scrolltopcontrol.js" > var scrolltotop={ Startline:integer. Number of pixels from top of doc ScrollBar are scrolled before showing control Scrollto:keyword (Integer, or "scroll_to_element_id"). How far to scroll the document up as control was clicked on (0=top). Setting: {startline:100, scrollto:0, scrollduration:1000, fadeduration:[500, 100]}, controlhtml: ' Controlattrs: {offsetx:5, offsety:5},//offset of control relative to right/bottom of window corner Anchorkeyword: ' #top ',//enter href value of HTML anchors on the page so should also act as "Scroll up" links State: {isvisible:false, shouldvisible:false}, scrollup:function () { if (!this.cssfixedsupport)//if control is positioned using JavaScript this. $control. css ({opacity:0})//hide control immediately after clicking it var Dest=isnan (This.setting.scrollto)? This.setting.scrollto:parseInt (This.setting.scrollto) if (typeof dest== "string" && jQuery (' # ' +dest '. length==1)//check element set by string exists 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" && windows. XMLHttpRequest//not IE or ie7+ browsers in standards mode 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: ' Scroll Back to Top '}) . Click (function () {mainobj.scrollup (); return false}) . Appendto (' body ') if (document.all &&!window. XMLHttpRequest && mainobj. $control. Text ()!= ')//loose check for IE6 and below, plus whether control contains any Text Mainobj. $control. css ({width:mainobj. $control. Width ()})//ie6-seems to require a explicit width on a DIV containing text Mainobj.togglecontrol () $ (' a[href= ' + Mainobj.anchorkeyword + ' "]"). Click (function () { Mainobj.scrollup () return False }) $ (window). bind (' Scroll resize ', function (e) { Mainobj.togglecontrol () }) }) } } Scrolltotop.init () </script> Setting: {startline:100, scrollto:0, scrollduration:1000, fadeduration:[500, 100]}, controlhtml: ' Controlattrs: {offsetx:15, offsety:15},//offset of control relative to right/bottom of window corner Anchorkeyword: ' #top ',//enter href value of HTML anchors on the page so should also act as "Scroll up" links |