[JavaScript] 圆周运动 →→→→→进入此内容的聊天室

来自 , 2021-03-29, 写在 JavaScript, 查看 139 次.
URL http://www.code666.cn/view/def7924e
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>圆周运动</title>
  6. <style>
  7. body {
  8.         background:#16171B;
  9. }
  10. #demo {
  11.         width:100px;
  12.         height:100px;
  13.         border-radius:100px;
  14.         border:3px solid #D6D8ED;
  15.         margin:50px auto;
  16.         box-shadow:inset 10px 10px 10px #0B090C, inset -10px -10px 10px #0B090C, 3px 0px 60px rgba(74, 94, 157, .8), 0px -5px 60px rgba(74, 94, 157, .8);
  17.         position:absolute;
  18.         top:300px;
  19.         left:500px;
  20.         background-color: #999;
  21. }
  22. </style>
  23. </head>
  24. <body>
  25. <div id="demo"> </div>
  26. <script type="text/javascript">
  27. function circle(id, R, speed, time) {
  28.         speed = speed || 10;
  29.         time = time;
  30.         var x = document.getElementById(id).offsetLeft;
  31.         var y = document.getElementById(id).offsetTop;
  32.         var step = 1;
  33.         var r = 1;
  34.         var timer = setInterval(function() {
  35.                 r = r + 1;
  36.                 if (r > R) {
  37.                         r -= 1;
  38.                 }
  39.                 if (step == 360) {
  40.                         step = 1;
  41.                 }
  42.                 if (time != undefined) {
  43.                         setTimeout(function() {
  44.                                 clearInterval(timer);
  45.                         }, time);
  46.                 }
  47.                 document.getElementById(id).style.left = x + r * Math.sin(step) + "px";
  48.                 document.getElementById(id).style.top = y + r * Math.cos(step) + "px";
  49.                 step -= speed / 100;
  50.         }, 1);
  51. }
  52. circle("demo", 300, 1);
  53. </script>
  54. </body>
  55. </html>

回复 "圆周运动"

这儿你可以回复上面这条便签

captcha