jdobry

Untitled

Feb 20th, 2026
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.41 KB | None | 0 0
  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>Analog Clock</title>
  7.     <style>
  8.         body {
  9.             margin: 0;
  10.             padding: 0;
  11.             display: flex;
  12.             justify-content: center;
  13.             align-items: center;
  14.             min-height: 100vh;
  15.             background-color: white;
  16.         }
  17.  
  18.         .clock {
  19.             width: 300px;
  20.             height: 300px;
  21.             border: 10px solid #333;
  22.             border-radius: 50%;
  23.             position: relative;
  24.             background-color: #fff;
  25.             box-shadow: 0 0 20px rgba(0,0,0,0.2);
  26.         }
  27.  
  28.         .clock-face {
  29.             position: relative;
  30.             width: 100%;
  31.             height: 100%;
  32.             transform: translateY(-50%);
  33.         }
  34.  
  35.         .number {
  36.             position: absolute;
  37.             width: 100%;
  38.             height: 100%;
  39.             text-align: center;
  40.             font-size: 24px;
  41.             font-weight: bold;
  42.             font-family: Arial, sans-serif;
  43.             color: #333;
  44.         }
  45.  
  46.         .number span {
  47.             display: block;
  48.             padding-top: 10px;
  49.         }
  50.  
  51.         .hand {
  52.             position: absolute;
  53.             bottom: 50%;
  54.             left: 50%;
  55.             transform-origin: bottom center;
  56.             transform: translateX(-50%);
  57.             border-top-left-radius: 10px;
  58.             border-top-right-radius: 10px;
  59.             z-index: 10;
  60.         }
  61.  
  62.         .hour {
  63.             width: 8px;
  64.             height: 70px;
  65.             background-color: #333;
  66.         }
  67.  
  68.         .minute {
  69.             width: 6px;
  70.             height: 100px;
  71.             background-color: #666;
  72.         }
  73.  
  74.         .second {
  75.             width: 2px;
  76.             height: 120px;
  77.             background-color: #f00;
  78.             z-index: 11;
  79.         }
  80.  
  81.         .center-dot {
  82.             width: 16px;
  83.             height: 16px;
  84.             background-color: #333;
  85.             border-radius: 50%;
  86.             position: absolute;
  87.             top: 50%;
  88.             left: 50%;
  89.             transform: translate(-50%, -50%);
  90.             z-index: 12;
  91.         }
  92.  
  93.         .ticks {
  94.             position: absolute;
  95.             width: 100%;
  96.             height: 100%;
  97.         }
  98.  
  99.         .tick {
  100.             position: absolute;
  101.             width: 4px;
  102.             height: 10px;
  103.             background-color: #333;
  104.             left: 50%;
  105.             top: 0;
  106.             transform-origin: center 150px;
  107.         }
  108.  
  109.         .long-tick {
  110.             width: 6px;
  111.             height: 15px;
  112.         }
  113.     </style>
  114. </head>
  115. <body>
  116.     <div class="clock">
  117.         <div class="clock-face">
  118.             <div class="ticks" id="ticks"></div>
  119.             <div class="number" style="transform: rotate(30deg);"><span>1</span></div>
  120.             <div class="number" style="transform: rotate(60deg);"><span>2</span></div>
  121.             <div class="number" style="transform: rotate(90deg);"><span>3</span></div>
  122.             <div class="number" style="transform: rotate(120deg);"><span>4</span></div>
  123.             <div class="number" style="transform: rotate(150deg);"><span>5</span></div>
  124.             <div class="number" style="transform: rotate(180deg);"><span>6</span></div>
  125.             <div class="number" style="transform: rotate(210deg);"><span>7</span></div>
  126.             <div class="number" style="transform: rotate(240deg);"><span>8</span></div>
  127.             <div class="number" style="transform: rotate(270deg);"><span>9</span></div>
  128.             <div class="number" style="transform: rotate(300deg);"><span>10</span></div>
  129.             <div class="number" style="transform: rotate(330deg);"><span>11</span></div>
  130.             <div class="number" style="transform: rotate(0deg);"><span>12</span></div>
  131.            
  132.             <div class="hand hour" id="hourHand"></div>
  133.             <div class="hand minute" id="minuteHand"></div>
  134.             <div class="hand second" id="secondHand"></div>
  135.             <div class="center-dot"></div>
  136.         </div>
  137.     </div>
  138.  
  139.     <script>
  140.         // Create ticks for the clock
  141.         const ticksContainer = document.getElementById('ticks');
  142.         for (let i = 0; i < 60; i++) {
  143.            const tick = document.createElement('div');
  144.            tick.className = i % 5 === 0 ? 'tick long-tick' : 'tick';
  145.            tick.style.transform = `rotate(${i * 6}deg)`;
  146.            ticksContainer.appendChild(tick);
  147.        }
  148.  
  149.        function updateClock() {
  150.            const now = new Date();
  151.            const seconds = now.getSeconds();
  152.            const minutes = now.getMinutes();
  153.            const hours = now.getHours();
  154.            
  155.            const secondDegrees = (seconds / 60) * 360;
  156.            const minuteDegrees = ((minutes + seconds / 60) / 60) * 360;
  157.            const hourDegrees = ((hours + minutes / 60) / 12) * 360;
  158.            
  159.            document.getElementById('secondHand').style.transform = `translateX(-50%) rotate(${secondDegrees}deg)`;
  160.            document.getElementById('minuteHand').style.transform = `translateX(-50%) rotate(${minuteDegrees}deg)`;
  161.            document.getElementById('hourHand').style.transform = `translateX(-50%) rotate(${hourDegrees}deg)`;
  162.        }
  163.  
  164.        setInterval(updateClock, 1000);
  165.        updateClock(); // Initial call to set the time immediately
  166.    </script>
  167. </body>
  168. </html>
Advertisement
Add Comment
Please, Sign In to add comment