UNPKG

fd-gulp-convert-encoding

Version:

convert file to assigned charset

102 lines (76 loc) 2.11 kB
;(function($){ var self; var defConfig = { "element": "#floating_box", //��Ҫ�����Ļض������� "position": "right", "contanerEle": "div.screen", //�������� "goTopBtn": "a.goTopBtn", //��Ҫ���¼���Ԫ�� "distance": 5 //�ض�������������ظ���Ԫ�������ľ��� } var GoTop = { init: function(){ self = this; self.isIE6 = false; self.goTopWrap = $(defConfig.element); self.fromBottom = self.goTopWrap.css("bottom"); if( $.browser.version === "6.0" ) { self.isIE6 = true; self.fromTop = $(window).height() - parseInt(self.fromBottom,10) - 50; }else{ self.isIE6 = false; } self._bindEvent(); self._setXPosition(); $(window).trigger("scroll"); }, _bindEvent: function() { $(window).bind("scroll",function(){ if( $(window).scrollTop() > 0 ){ self.goTopWrap.fadeIn(); }else{ self.goTopWrap.fadeOut(); } if( self.isIE6 ){ self._fixIE6(); } }); $(window).bind("resize",function(){ if( self.isIE6 ){ self._fixIE6(); } if( defConfig.position === "right" ){ self._setXPosition(); } }); $(defConfig.goTopBtn,defConfig.element).click(function(e){ e.preventDefault(); $('body,html').animate({ "scrollTop": 0 },300,'linear'); }); }, _setXPosition: function() { var contentwidth = $(defConfig.contanerEle).outerWidth(), viewWidth = $(document.body).width(), blankSpace = (viewWidth - contentwidth) / 2, toLeft = 0; if( defConfig.position === "left" ) { toLeft = Math.floor(blankSpace) - $(defConfig.element).outerWidth() - defConfig.distance; }else{ toLeft = Math.floor(blankSpace) + Math.floor(contentwidth) + defConfig.distance; } self.goTopWrap.css("left",toLeft); }, _fixIE6: function() { var top = $(window).scrollTop() + self.fromTop; self.goTopWrap.css({ "position": "absolute", "top": top }); }, end: 0 }; $(function(){ GoTop.init(); }) })(jQuery);