jdobry

Untitled

Feb 26th, 2026
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.80 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>Interactive Analog Clock</title>
  7.     <style>
  8.         body {
  9.             display: flex;
  10.             justify-content: center;
  11.             align-items: center;
  12.             height: 100vh;
  13.             background-color: #f0f0f0; /* Light gray body to make the white clock pop */
  14.             margin: 0;
  15.             font-family: sans-serif;
  16.         }
  17.  
  18.         .clock-container {
  19.             position: relative;
  20.         }
  21.  
  22.         .clock {
  23.             width: 300px;
  24.             height: 300px;
  25.             background-color: white;
  26.             border-radius: 50%;
  27.             border: 15px solid #333;
  28.             position: relative;
  29.             box-shadow: 0 0 20px rgba(0,0,0,0.1);
  30.             cursor: pointer;
  31.             transition: transform 0.3s ease;
  32.         }
  33.  
  34.         .clock:active {
  35.             transform: scale(0.95);
  36.         }
  37.  
  38.         .center-dot {
  39.             position: absolute;
  40.             width: 16px;
  41.             height: 16px;
  42.             background-color: #333;
  43.             border-radius: 50%;
  44.             top: 50%;
  45.             left: 50%;
  46.             transform: translate(-50%, -50%);
  47.             z-index: 10;
  48.         }
  49.  
  50.         .hand {
  51.             position: absolute;
  52.             bottom: 50%;
  53.             left: 50%;
  54.             transform-origin: bottom center;
  55.             border-radius: 4px;
  56.             z-index: 5;
  57.         }
  58.  
  59.         .hour-hand {
  60.             width: 8px;
  61.             height: 70px;
  62.             background-color: #333;
  63.             margin-left: -4px; /* Center alignment */
  64.         }
  65.  
  66.         .minute-hand {
  67.             width: 6px;
  68.             height: 100px;
  69.             background-color: #555;
  70.             margin-left: -3px;
  71.         }
  72.  
  73.         .second-hand {
  74.             width: 2px;
  75.             height: 110px;
  76.             background-color: #e74c3c;
  77.             margin-left: -1px;
  78.             z-index: 6;
  79.         }
  80.  
  81.         .marker {
  82.             position: absolute;
  83.             width: 4px;
  84.             height: 100%;
  85.             left: 50%;
  86.             transform: translateX(-50%);
  87.             pointer-events: none;
  88.         }
  89.         .marker-top { top: 0; }
  90.         .marker-bottom { bottom: 0; }
  91.  
  92.         .center-circle {
  93.             position: absolute;
  94.             width: 100%;
  95.             height: 100%;
  96.             top: 0;
  97.             left: 0;
  98.             pointer-events: none;
  99.         }
  100.  
  101.         .label {
  102.             text-align: center;
  103.             margin-top: 20px;
  104.             color: #333;
  105.             font-size: 1rem;
  106.             font-weight: bold;
  107.         }
  108.  
  109.         .stopwatch-overlay {
  110.             display: none;
  111.             width: 100%;
  112.             height: 100%;
  113.             background: rgba(255, 255, 255, 0.5);
  114.             position: absolute;
  115.             top: 0;
  116.             left: 0;
  117.             border-radius: 50%;
  118.             cursor: pointer;
  119.         }
  120.  
  121.         .stopwatch-overlay span {
  122.             position: absolute;
  123.             top: 50%;
  124.             left: 50%;
  125.             transform: translate(-50%, -50%);
  126.             font-size: 1.2rem;
  127.             font-weight: bold;
  128.             color: #333;
  129.             pointer-events: none;
  130.         }
  131.     </style>
  132. </head>
  133. <body>
  134.  
  135.     <div class="clock-container">
  136.         <div class="clock" id="clockFace">
  137.             <div class="marker marker-top"></div>
  138.             <div class="marker marker-bottom"></div>
  139.            
  140.             <div class="hand hour-hand" id="hourHand"></div>
  141.             <div class="hand minute-hand" id="minuteHand"></div>
  142.             <div class="hand second-hand" id="secondHand"></div>
  143.             <div class="center-dot"></div>
  144.         </div>
  145.        
  146.         <div class="stopwatch-overlay" id="overlay">
  147.             <span>Click to Pause/Start</span>
  148.         </div>
  149.     </div>
  150.     <div class="label">Current Time</div>
  151.  
  152.     <script>
  153.         const hourHand = document.getElementById('hourHand');
  154.         const minuteHand = document.getElementById('minuteHand');
  155.         const secondHand = document.getElementById('secondHand');
  156.         const clockFace = document.getElementById('clockFace');
  157.         const overlay = document.getElementById('overlay');
  158.  
  159.         let isRunning = true;
  160.         let clockInterval;
  161.  
  162.         function updateClock() {
  163.             const now = new Date();
  164.             const seconds = now.getSeconds();
  165.             const minutes = now.getMinutes();
  166.             const hours = now.getHours();
  167.  
  168.             // Calculate degrees
  169.             const secondsDegrees = ((seconds / 60) * 360);
  170.             const minutesDegrees = ((minutes / 60) * 360) + ((seconds/60)*6);
  171.             const hoursDegrees = ((hours / 12) * 360) + ((minutes/60)*30);
  172.  
  173.             // Apply rotation
  174.             secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
  175.             minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
  176.             hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
  177.         }
  178.  
  179.         function startClock() {
  180.             if (!isRunning) {
  181.                 updateClock();
  182.                 isRunning = true;
  183.                 overlay.style.display = 'none';
  184.             }
  185.         }
  186.  
  187.         function stopClock() {
  188.             if (isRunning) {
  189.                 isRunning = false;
  190.                 overlay.style.display = 'flex';
  191.             }
  192.         }
  193.  
  194.         function toggleClock() {
  195.             if (isRunning) {
  196.                 stopClock();
  197.             } else {
  198.                 startClock();
  199.             }
  200.         }
  201.  
  202.         clockFace.addEventListener('click', toggleClock);
  203.  
  204.         // Initialize
  205.         updateClock();
  206.         // Update every second
  207.         clockInterval = setInterval(updateClock, 1000);
  208.  
  209.     </script>
  210. </body>
  211. </html>
Advertisement
Add Comment
Please, Sign In to add comment