首页 > Web开发 > 详细

Js运动框架

时间:2016-04-08 11:39:03      阅读:190      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!