JS原生之--圆周运动(转转转)

21 篇文章 0 订阅
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>四个小球椭圆运动</title>
		<style type="text/css">
			.ball{border-radius:50%;}
			.bg{margin:80px;width:550px;height:200px;border:1px solid #ccc;background:greenyellow;}
			.box{position: relative;margin:34px;}
		</style>
		<script>
			οnlοad=function(){
				var balls = document.getElementsByClassName("ball");
				for(var i =0;i<balls.length;i++){
					balls[i].deg = i *45; 	
				}
				var a = 300,b=100
				setInterval(function(){
					for(var i =0;i<balls.length;i++){
						balls[i].style.left = a *Math.cos(balls[i].deg *Math.PI /180) +a +"px";
						balls[i].style.top = b *Math.sin(balls[i].deg *Math.PI/180) +b +"px";	
						balls[i].deg+=2;
						balls[i].style.width = balls[i].style.height = balls[i].offsetTop /5 +30+"px";
					}	
				},20)
				
			}
		</script>
	</head>
	<body>
		<div class="box">
		<div class="ball" style="position: absolute; background: red; left:600px; top:0;  width: 30px; height: 30px; ">
		</div>
		<div class="ball" style="position: absolute; background: blue; left:1200px; top:300px;  width: 30px; height: 30px; ">
		</div>
		<div class="ball" style="position: absolute; background: yellow; left:600px; top:600px;  width: 30px; height: 30px; ">
		</div>
		<div class="ball" style="position: absolute; background: black; left:0; top:300px;  width: 30px; height: 30px; ">
		</div>
		<div class="ball" style="position: absolute; background: orange; left:0; top:300px;  width: 30px; height: 30px; ">
		</div>
		<div class="ball" style="position: absolute; background: pink; left:0; top:300px;  width: 30px; height: 30px; ">
		</div>
		<div class="ball" style="position: absolute; background: deepskyblue; left:0; top:300px;  width: 30px; height: 30px; ">
		</div>
		<div class="ball" style="position: absolute; background: purple; left:0; top:300px;  width: 30px; height: 30px; ">
		</div>
		</div>
		<div class="bg"></div>
	</body>
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值