摘要:JS代码实现圆周运动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>

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>

觉得可用,就经常来吧!Javascript技巧 脚本宝典 欢迎评论哦! js技巧,巧夺天工,精雕玉琢。小宝典献丑了!

本文固定链接:

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

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

80%的人都看过