用做運動的小球遊戲

<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<div  id="div1"  style="position: absolute; background: red; width: 500px;  height: 500px;"></div>
		<div   id="div2"   style="position: absolute;  background: blueviolet; width: 50px; height: 50px; border-radius: 50%;"> </div>
		<script>
			var di1=document.getElementById("div1");
			
			var count=0;
			var hei=0;
			var vgfb =50;
			var bool=true;
			var  setInterVal =setInterval(function(){
				var di2=document.getElementById("div2");
				if(hei<=0||count<=0){
					bool=true;
				}
				if(hei>=450||count>=450 ){
					bool=false;
					
				}
				if(bool){
					count=count+vgfb;
					hei=hei+vgfb;
					div2.style.left=count+"px";
				    div2.style.top=hei+"px";
				}
				else{
					count=count-vgfb;
					hei=hei-vgfb;
					div2.style.left=count+"px";
				    div2.style.top=hei+"px";
				}
			},1000)
		</script>
	</body>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章