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

Js运动框架

时间:2016-04-08 11:39:26      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
<div id="div1" style="width: 100px;height: 100px;background: red;position: absolute;top:0;left: 0;"></div>
</body>
<script type="text/javascript">
	function animate(ele,attr,value){
		var speed;
		var timer=null;
		(function(){
			clearInterval(timer);
			timer=setInterval(function(){
				var now=parseInt(ele.style[attr]);
				speed=(value-now)/10;
				speed=speed>0?Math.ceil(speed):Math.floor(speed);
				if(now!=value){
					ele.style[attr]=now+speed+‘px‘;
				}else{
					clearInterval(timer);
				}
			},30);
		})();
		
	}
	var div = document.getElementById("div1");
	animate(div,‘top‘,200);
	animate(div,‘left‘,100);
</script>
</html>

  

Js运动框架

标签:

原文地址:http://www.cnblogs.com/hongrunhui/p/5367149.html

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