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>`

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>`

# js实例教程-JS代码实现圆周运动

http://www.js-code.com/js/js_1151.html