animate

function animate(args){
	//保存运动对象
	this.animateTarget=args.obj;
	//保存运动的属性
	this.animateProperty=args.property;
	//保存速度
	this.animaterSpeed=args.speed||6;
	//保存回调函数
	this.callBack=args.callBack||false;
	//初始化动画
	this.initAnimate();
};
animate.prototype={
	initAnimate:function(){
		var _this=this,speed;
		window.clearInterval(this.animateTarget.timer);
		this.animateTarget.timer=window.setInterval(function(){
			var isClear=true;
			for(var prop in _this.animateProperty){
				speed=(_this.animateProperty[prop]-_this.getCurrentStyleValue(prop))/(10-_this.animaterSpeed);
				speed=speed>0?Math.ceil(speed):Math.floor(speed);
				if(_this.getCurrentStyleValue(prop)!=_this.animateProperty[prop]){
					isClear=false;
				};
				if(Math.abs(_this.getCurrentStyleValue(prop)-_this.animateProperty[prop])<=_this.animaterSpeed){
					_this.animateTarget.style[prop]=_this.animateProperty[prop]+"px";
				}else{
					_this.animateTarget.style[prop]=_this.getCurrentStyleValue(prop)+speed+"px";
				};
			};
			if(isClear){
				window.clearInterval(_this.animateTarget.timer);
				if(_this.callBack){_this.callBack.call(_this.animateTarget)};
			};
		},13);
	},
	//获取当前属性的属性值
	getCurrentStyleValue:function(property){
		var result;
		if(window.getComputedStyle){
			result=window.getComputedStyle(this.animateTarget,null)[property];
		}else{
			result=this.animateTarget.currentStyle[property];
		};
		return parseInt(result);
	}
};

  

	boxs[i].onclick=function(){
		new animate({
					obj:this,
					property:{
							marginLeft:400,
							height:100
							},
					speed:3,
					callBack:function(){
						//alert(this);
					}
				});
	}

  

转载于:https://www.cnblogs.com/yangliulang/p/3313938.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值