showSlip对象的作用就是控制Div层的滑动;

/*
 * 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);}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值