/* * showSlip对象的作用就是控制Div层的滑动; * @__name 所要滑动对象的ID名称; * @__sign “0”表示上下滑动,“1”表示左右滑动; * @__delay 此值是控制步长的,每次滑动的步长就是到终点所剩距离的__delay分之一,默认值(4); * @__time 滑动间隔时间,默认值(40); */ function showSlip(__name, __sign, __delay, __time){ this.moveObj = document.getElementById(__name); //所要滑动的对象; this.moveSize = 500; //每一次滑动的距离; this.moveType = 1; //1表是正向滑动,-1表是反向滑动; this.moveSign = __sign; //0表示top属性,1表示left属性; this.endPlace =parseInt( (this.moveSign==0)?this.moveObj.style.top:this.moveObj.style.left); //滑动结束位置; this.currPlace = this.endPlace; //滑动当前位置; this.finishCallback=function(){}; this.moveLoad = null; this.spaceTime = __time; //滑动间隔时间,默认值(40); this.delayValue= __delay; //此值是控制步长的,每次滑动的步长就是到终点所剩距离的this.delayValue分之一,默认值(4); //开始滑动对象 this.moveStart = function(__type, __size){ this.moveStop(); this.moveType = __type; this.moveSize = __size; this.endPlace += this.moveSize*this.moveType; this.moveGoto(); } //计算当前要滑动的位置 this.moveGoto = function(){ var tempStep = Math.ceil(Math.abs((this.endPlace-this.currPlace)/this.delayValue))*this.moveType; //计算步长 this.currPlace += tempStep; if((this.moveType==-1&&this.currPlace<=this.endPlace)||(this.moveType==1&&this.currPlace>=this.endPlace)||tempStep==0){ //判断是否到达终点 this.currPlace = this.endPlace; this.setcurrPlace(); this.finishCallback(); }else{ var self = this; this.setcurrPlace(); this.moveLoad = window.setTimeout(function(){self.moveGoto();},this.spaceTime); } } //设置滑动对象的位置 this.setcurrPlace = function(){ if(this.moveSign==0){ this.moveObj.style.top = this.currPlace+"px"; }else{ this.moveObj.style.left= this.currPlace+"px"; } } //调整对象位置,参数__num是将要调整位置的值 this.tunePlace = function(__num){ this.endPlace = __num; this.currPlace = this.endPlace; this.setcurrPlace(); } //对象停止滑动 this.moveStop = function(){ window.clearTimeout(this.moveLoad);} }