Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Interactive Analog Clock</title>
- <style>
- body {
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100vh;
- background-color: #f0f0f0; /* Light gray body to make the white clock pop */
- margin: 0;
- font-family: sans-serif;
- }
- .clock-container {
- position: relative;
- }
- .clock {
- width: 300px;
- height: 300px;
- background-color: white;
- border-radius: 50%;
- border: 15px solid #333;
- position: relative;
- box-shadow: 0 0 20px rgba(0,0,0,0.1);
- cursor: pointer;
- transition: transform 0.3s ease;
- }
- .clock:active {
- transform: scale(0.95);
- }
- .center-dot {
- position: absolute;
- width: 16px;
- height: 16px;
- background-color: #333;
- border-radius: 50%;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- z-index: 10;
- }
- .hand {
- position: absolute;
- bottom: 50%;
- left: 50%;
- transform-origin: bottom center;
- border-radius: 4px;
- z-index: 5;
- }
- .hour-hand {
- width: 8px;
- height: 70px;
- background-color: #333;
- margin-left: -4px; /* Center alignment */
- }
- .minute-hand {
- width: 6px;
- height: 100px;
- background-color: #555;
- margin-left: -3px;
- }
- .second-hand {
- width: 2px;
- height: 110px;
- background-color: #e74c3c;
- margin-left: -1px;
- z-index: 6;
- }
- .marker {
- position: absolute;
- width: 4px;
- height: 100%;
- left: 50%;
- transform: translateX(-50%);
- pointer-events: none;
- }
- .marker-top { top: 0; }
- .marker-bottom { bottom: 0; }
- .center-circle {
- position: absolute;
- width: 100%;
- height: 100%;
- top: 0;
- left: 0;
- pointer-events: none;
- }
- .label {
- text-align: center;
- margin-top: 20px;
- color: #333;
- font-size: 1rem;
- font-weight: bold;
- }
- .stopwatch-overlay {
- display: none;
- width: 100%;
- height: 100%;
- background: rgba(255, 255, 255, 0.5);
- position: absolute;
- top: 0;
- left: 0;
- border-radius: 50%;
- cursor: pointer;
- }
- .stopwatch-overlay span {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- font-size: 1.2rem;
- font-weight: bold;
- color: #333;
- pointer-events: none;
- }
- </style>
- </head>
- <body>
- <div class="clock-container">
- <div class="clock" id="clockFace">
- <div class="marker marker-top"></div>
- <div class="marker marker-bottom"></div>
- <div class="hand hour-hand" id="hourHand"></div>
- <div class="hand minute-hand" id="minuteHand"></div>
- <div class="hand second-hand" id="secondHand"></div>
- <div class="center-dot"></div>
- </div>
- <div class="stopwatch-overlay" id="overlay">
- <span>Click to Pause/Start</span>
- </div>
- </div>
- <div class="label">Current Time</div>
- <script>
- const hourHand = document.getElementById('hourHand');
- const minuteHand = document.getElementById('minuteHand');
- const secondHand = document.getElementById('secondHand');
- const clockFace = document.getElementById('clockFace');
- const overlay = document.getElementById('overlay');
- let isRunning = true;
- let clockInterval;
- function updateClock() {
- const now = new Date();
- const seconds = now.getSeconds();
- const minutes = now.getMinutes();
- const hours = now.getHours();
- // Calculate degrees
- const secondsDegrees = ((seconds / 60) * 360);
- const minutesDegrees = ((minutes / 60) * 360) + ((seconds/60)*6);
- const hoursDegrees = ((hours / 12) * 360) + ((minutes/60)*30);
- // Apply rotation
- secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
- minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
- hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
- }
- function startClock() {
- if (!isRunning) {
- updateClock();
- isRunning = true;
- overlay.style.display = 'none';
- }
- }
- function stopClock() {
- if (isRunning) {
- isRunning = false;
- overlay.style.display = 'flex';
- }
- }
- function toggleClock() {
- if (isRunning) {
- stopClock();
- } else {
- startClock();
- }
- }
- clockFace.addEventListener('click', toggleClock);
- // Initialize
- updateClock();
- // Update every second
- clockInterval = setInterval(updateClock, 1000);
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment