码迷,mamicode.com
首页 > Web开发 > 详细

js运动函数

时间:2015-05-13 00:35:21      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:

function doMove ( obj, attr, dir, target, callback ) {
	
	dir = parseInt(getStyle( obj, attr )) < target ? dir : -dir;
	
	clearInterval( obj.timer );
	
	obj.timer = setInterval(function () {
		
		var speed = parseInt(getStyle( obj, attr )) + dir;			// 步长
		
		if ( speed > target && dir > 0 ||  speed < target && dir < 0  ) {
			speed = target;
		}
		
		obj.style[attr] = speed + ‘px‘;
		
		if ( speed == target ) {
			clearInterval( obj.timer );
			
			callback && callback();
			
		}
		
	}, 30);
}

function getStyle ( obj, attr ) { return obj.currentStyle?obj.currentStyle[attr] : getComputedStyle( obj )[attr]; }

  

js运动函数

标签:

原文地址:http://www.cnblogs.com/micotan/p/4499047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!