JS代码实现圆周运动
程序员文章站
2022-03-03 22:47:13
js代码实现圆周运动
js代码实现圆周运动
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> body{ margin: 0; padding: 0; } #circle{ position: relative; width: 300px; height: 300px; background: #f2f2f2; border-radius: 50%; } #ball{ position: absolute; width: 10px; height: 10px; margin-left: -5px; margin-top: -5px; background: red; border-radius: 50%; } </style> </head> <body> <p id="circle"> <p id="ball"></p> </p> <script type="text/javascript"> var ocircle = document.getelementbyid("circle"); var oball = document.getelementbyid("ball"); var r = ocircle.offsetwidth/2; var angle = 0; var timer = setinterval(function(){ angle++; var hd = math.pi/180*angle; var x = r*math.cos(hd); var y = r*math.sin(hd); oball.style.left =r+ x + "px"; oball.style.top =r- y + "px"; },30) </script> </body> </html>
上一篇: SE发布免费动作手游《古墓丽影:重装上阵》:画质辣眼
下一篇: JS位移问题-移位操作方法