Guest User

Untitled

a guest
Nov 15th, 2025
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Analog Clock</title>
  6. <style>
  7. body {
  8. display: flex;
  9. justify-content: center;
  10. align-items: center;
  11. height: 100vh;
  12. background-color: #f4f4f4;
  13. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  14. }
  15. .clock {
  16. width: 400px;
  17. height: 400px;
  18. border-radius: 50%;
  19. background-color: white;
  20. border: 2px solid #333;
  21. position: relative;
  22. box-shadow: 0 10px 30px rgba(0,0,0,0.1);
  23. }
  24. .number {
  25. position: absolute;
  26. width: 30px;
  27. height: 30px;
  28. text-align: center;
  29. color: #333;
  30. font-weight: 300;
  31. }
  32. .hand {
  33. position: absolute;
  34. bottom: 50%;
  35. left: 50%;
  36. transform-origin: bottom;
  37. background-color: #333;
  38. }
  39. .hour-hand {
  40. width: 6px;
  41. height: 25%;
  42. border-radius: 4px;
  43. }
  44. .minute-hand {
  45. width: 4px;
  46. height: 35%;
  47. border-radius: 3px;
  48. }
  49. .second-hand {
  50. width: 2px;
  51. height: 40%;
  52. background-color: #e74c3c;
  53. }
  54. </style>
  55. </head>
  56. <body>
  57. <div class="clock" id="clock">
  58. <div class="hand hour-hand" id="hourHand"></div>
  59. <div class="hand minute-hand" id="minuteHand"></div>
  60. <div class="hand second-hand" id="secondHand"></div>
  61. </div>
  62.  
  63. <script>
  64. const clock = document.getElementById('clock');
  65. const hourHand = document.getElementById('hourHand');
  66. const minuteHand = document.getElementById('minuteHand');
  67. const secondHand = document.getElementById('secondHand');
  68.  
  69. // Position numbers
  70. const numbers = [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
  71. numbers.forEach((num, index) => {
  72. const numberEl = document.createElement('div');
  73. numberEl.classList.add('number');
  74. numberEl.innerText = num;
  75.  
  76. const angle = index * 30;
  77. const radius = 180;
  78. const x = 200 + radius * Math.sin(angle * Math.PI / 180) - 15;
  79. const y = 200 - radius * Math.cos(angle * Math.PI / 180) - 15;
  80.  
  81. numberEl.style.left = `${x}px`;
  82. numberEl.style.top = `${y}px`;
  83. clock.appendChild(numberEl);
  84. });
  85.  
  86. function updateClock() {
  87. const now = new Date();
  88. const seconds = now.getSeconds();
  89. const minutes = now.getMinutes();
  90. const hours = now.getHours() % 12;
  91.  
  92. const secondDegrees = seconds * 6;
  93. const minuteDegrees = minutes * 6 + seconds * 0.1;
  94. const hourDegrees = hours * 30 + minutes * 0.5;
  95.  
  96. secondHand.style.transform = `rotate(${secondDegrees}deg)`;
  97. minuteHand.style.transform = `rotate(${minuteDegrees}deg)`;
  98. hourHand.style.transform = `rotate(${hourDegrees}deg)`;
  99. }
  100.  
  101. setInterval(updateClock, 1000);
  102. updateClock(); // Immediate first call
  103. </script>
  104. </body>
  105. </html>
Advertisement
Add Comment
Please, Sign In to add comment