gusucode.com > 230_蓝色IT公司背景会动 html64精品模板 > 230_蓝色IT公司背景会动/style/jquery.scrolltotop.js

    // Powered by Junlens
// Copyright(c)2013 junlens.com All Rights Reserved.

var scrolltotop={setting:{startline:1,scrollto:0,scrollduration:1000,fadeduration:[500,100]},controlHTML:'<img src="/images/scrolltop.png" style="width:40px; height:40px" />',controlattrs:{offsetx:5,offsety:5},anchorkeyword:"#top",state:{isvisible:false,shouldvisible:false},scrollup:function(){if(!this.cssfixedsupport){this.$control.css({opacity:0})}var A=isNaN(this.setting.scrollto)?this.setting.scrollto:parseInt(this.setting.scrollto);if(typeof A=="string"&&jQuery("#"+A).length==1){A=jQuery("#"+A).offset().top}else{A=0}this.$body.animate({scrollTop:A},this.setting.scrollduration)},keepfixed:function(){var A=jQuery(window);var B=A.scrollLeft()+A.width()-this.$control.width()-this.controlattrs.offsetx;var C=A.scrollTop()+A.height()-this.$control.height()-this.controlattrs.offsety;this.$control.css({left:B+"px",top:C+"px"})},togglecontrol:function(){var A=jQuery(window).scrollTop();if(!this.cssfixedsupport){this.keepfixed()}this.state.shouldvisible=(A>=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(B){var C=scrolltotop;var A=document.all;C.cssfixedsupport=!A||A&&document.compatMode=="CSS1Compat"&&window.XMLHttpRequest;C.$body=(window.opera)?(document.compatMode=="CSS1Compat"?B("html"):B("body")):B("html,body");C.$control=B('<div id="topcontrol">'+C.controlHTML+"</div>").css({position:C.cssfixedsupport?"fixed":"absolute",bottom:C.controlattrs.offsety,right:C.controlattrs.offsetx,opacity:0,cursor:"pointer"}).attr({title:"返回顶部"}).click(function(){C.scrollup();return false}).appendTo("body");if(document.all&&!window.XMLHttpRequest&&C.$control.text()!=""){C.$control.css({width:C.$control.width()})}C.togglecontrol();B('a[href="'+C.anchorkeyword+'"]').click(function(){C.scrollup();return false});B(window).bind("scroll resize",function(D){C.togglecontrol()})})}};scrolltotop.init();