Advertisement
JasonJJK

Analog clock

Feb 14th, 2025
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.73 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <script src="https://cdn.tailwindcss.com/"></script>
  8.     <title>analogclock v1.0.1</title>
  9. </head>
  10.  
  11. <body>
  12.  
  13.     <style>
  14.         #secondHand, #minuteHand, #hourHand {
  15.             transition: transform 1s linear;
  16.         }
  17.     </style>
  18.  
  19.     <!-- clock -->
  20.     <div id="clock"
  21.        class="mx-auto relative flex items-center justify-center size-[200px] m-2 rounded-full border-[1px] border-black">
  22.  
  23.         <div id="centerDot" class="absolute size-[8px]">
  24.             <div class="size-[8px] bg-black rounded-full"></div>
  25.         </div>
  26.  
  27.         <div id="minuteHand" class="absolute h-[150px] w-[3px]">
  28.             <div class="h-[75px] w-[3px] bg-black rounded-full"></div>
  29.         </div>
  30.  
  31.         <div id="hourHand" class="absolute h-[100px] w-[5px]">
  32.             <div class="h-[50px] w-[5px] bg-black rounded-full"></div>
  33.         </div>
  34.  
  35.         <div id="secondHand" class="absolute h-[180px] w-[1px]">
  36.             <div class="h-[90px] w-[1px] bg-black rounded-full"></div>
  37.         </div>
  38.  
  39.     </div>
  40.  
  41.     <script>
  42.         function updateClock() {
  43.             const d = new Date();
  44.             const sec = d.getSeconds();
  45.             const hour = d.getHours();
  46.             const mins = d.getMinutes();
  47.  
  48.             hourHand.style.transform = `rotate(${360 / 12 * hour + 360 / 12 / 60 * mins}deg)`
  49.             minuteHand.style.transform = `rotate(${360 / 60 * mins + 360 / 60 / 60 * sec}deg)`
  50.             secondHand.style.transform = `rotate(${360 / 60 * sec}deg)`
  51.         }
  52.  
  53.         updateClock()
  54.         setInterval(updateClock, 1000)
  55.     </script>
  56. </body>
  57.  
  58. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement