练习题1_时钟.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. ul{
  9. margin:0;
  10. padding: 0;
  11. }
  12. .box{
  13. width: 402px;
  14. height: 402px;
  15. border:1px dashed #000;
  16. margin:100px auto;
  17. }
  18. .clock{
  19. width: 400px;
  20. height: 400px;
  21. border:1px solid #000;
  22. border-radius: 50%;
  23. position: relative;
  24. }
  25. .clock li{
  26. list-style: none;
  27. width: 4px;
  28. height: 8px;
  29. background-color: #000;
  30. position: absolute;
  31. left: 50%;
  32. top: 0;
  33. transform-origin: 0 200px;
  34. }
  35. /* .clock li:nth-child(1){
  36. transform: rotate(0deg);
  37. }
  38. .clock li:nth-child(2){
  39. transform: rotate(6deg);
  40. }
  41. .clock li:nth-child(3){
  42. transform: rotate(12deg);
  43. } */
  44. .clock li:nth-child(5n+1){
  45. height: 16px;
  46. }
  47. </style>
  48. </head>
  49. <body>
  50. <div class="box">
  51. <div class="clock">
  52. <ul>
  53. </ul>
  54. </div>
  55. </div>
  56. <script>
  57. let oUl = document.getElementsByTagName("ul")[0];
  58. for(let i = 0;i<60;i++){
  59. let oLi = document.createElement("li");
  60. oLi.style.transform = `rotate(${i*6}deg)`;
  61. oUl.appendChild(oLi);
  62. }
  63. </script>
  64. </body>
  65. </html>