码迷,mamicode.com
首页 > 其他好文 > 详细

6.2.17 匀速运动案例

时间:2018-07-21 22:45:25      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:function   func   element   sha   none   interval   javascrip   wrap   cti   

 

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{padding: 0;margin: 0;}
			.box{
				width: 200px;
				height: 200px;
				background-color: #FF0000;
				position: absolute;
				top: 50px;
				left: 0px;
			}
		</style>
	</head>
	<body>
		<div id="wrap">
			
			<button id="btn">运动</button>
			<div class="box" id="box1">
				
			</div>
			
		</div>
	</body>
	<script type="text/javascript">
		var btn = document.getElementById(‘btn‘);
		
		var box1 = document.getElementById(‘box1‘)
		
		var count  = 0;
		var time = null;
		btn.onclick = function(){
			
			time = setInterval(function(){
				count+=10;
				if(count>1000){
					clearInterval(time)
					box1.style.display = ‘none‘
				}
				
				box1.style.left = count + ‘px‘				
				
			},10)
			
		}
	</script>
	
</html>

  

6.2.17 匀速运动案例

标签:function   func   element   sha   none   interval   javascrip   wrap   cti   

原文地址:https://www.cnblogs.com/beallaliu/p/9348072.html

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