function Slider(param1,param2){ // this.constructor.apply(this, arguments); this.constructor(param1,param2); } Slider.prototype = { el:null, initTop:null, interval:50, myInt:null, anim:true, sizeheight:100, position:"CENTER", POSITIONENT_CER:"CENTER", POSITION_TOP:"TOP", POSITION_BOTTOM:"BOTTOM", firstrender:true, isIE6:false, constructor:function(param1,param2) { this.el = param1; if(param2 != undefined) this.anim = param2; }, initialize:function() { this.isIE6 = /*@cc_on!@*/false; this.initTop = this.el.offsetTop || this.getTop( { el:this.el } ); if(this.anim){ this.el.style.position = 'absolute'; }else if(this.isIE6){ this.el.style.position = 'absolute'; }else{ this.el.style.position = 'fixed'; } try { if(this.anim) window.addEventListener('scroll', this.delegate(this,this.scrollEvent), false); else if(this.isIE6) window.addEventListener('scroll', this.delegate(this,this.scrollEvent),false); window.addEventListener('resize', this.delegate(this,this.scrollEvent), false); } catch (e) { if(this.anim) window.attachEvent('onscroll',this.delegate(this,this.scrollEvent)); else if(this.isIE6) window.attachEvent('onscroll',this.delegate(this,this.scrollEvent)); window.attachEvent('onresize',this.delegate(this,this.scrollEvent)); } this.scrollEvent(); this.el.style.visibility = 'visible'; }, scrollEvent:function() { var s = this; var trgSizeHeight = this.sizeheight; if(this.anim && !this.firstrender){ clearInterval(s.myInt); //center s.myInt = setInterval(function(){ var myTop = s.el.offsetTop || s.getTop( { el:s.el } ); var cur = s.getPositionTop(); if(s.position == s.POSITION_CENTER){ cur = cur + s.getWindowHeight() /2 - trgSizeHeight / 2; }else if(s.position == s.POSITION_TOP){ }else{ cur = cur + s.getWindowHeight() - trgSizeHeight; } var d = cur-myTop; if(Math.abs(d)>1) { if( cur >= s.initTop ) { var y = myTop + d/3; s.el.style.top = s.setPx(y); } else { s.el.style.top = s.setPx(s.initTop); clearInterval(s.myInt); } } else { s.el.style.top = s.setPx(cur); clearInterval(s.myInt); } },s.interval); }else{ if(this.isIE6){ var myTop = s.getPositionTop(); var cur; if(s.position == s.POSITION_CENTER){ cur = myTop + s.getWindowHeight() /2 - trgSizeHeight / 2; }else if(s.position == s.POSITION_TOP){ cur = myTop; }else{ cur = myTop + s.getWindowHeight() - trgSizeHeight; } }else{ var cur; if(s.position == s.POSITION_CENTER){ cur = s.getWindowHeight() /2 - trgSizeHeight / 2; }else if(s.position == s.POSITION_TOP){ cur = 0; }else{ cur = s.getWindowHeight() - trgSizeHeight; } } s.el.style.top = s.setPx(cur); } this.firstrender = false; }, getTop:function(args) { var el = args.el; var tagName = el.tagName; var top = args.top||0; if(tagName=='body'||tagName=='BODY') { return top; } else if(tagName=='html'||tagName=='HTML') { return top; } else { return arguments.callee( { el:el.offsetParent, top:top += el.offsetTop } ); } }, getPositionTop:function(){ return document.body.scrollTop || document.documentElement.scrollTop; }, getWindowHeight:function(){ return document.documentElement.clientHeight || document.body.clientHeight; }, /* utils */ setPx:function(num){ return (Math.round(num))+'px'; }, delegate:function( that, thatMethod ){ return function() { return thatMethod.call(that); } } }; function backToTop() { var x1 = x2 = x3 = 0; var y1 = y2 = y3 = 0; if (document.documentElement) { x1 = document.documentElement.scrollLeft || 0; y1 = document.documentElement.scrollTop || 0; } if (document.body) { x2 = document.body.scrollLeft || 0; y2 = document.body.scrollTop || 0; } x3 = window.scrollX || 0; y3 = window.scrollY || 0; var x = Math.max(x1, Math.max(x2, x3)); var y = Math.max(y1, Math.max(y2, y3)); window.scrollTo(Math.floor(x / 2), Math.floor(y / 2)); if (x > 0 || y > 0) { window.setTimeout(backToTop, 25); } }