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>Analog Clock</title>
- <style>
- body {
- margin: 0;
- padding: 0;
- display: flex;
- justify-content: center;
- align-items: center;
- min-height: 100vh;
- background-color: white;
- }
- .clock {
- width: 300px;
- height: 300px;
- border: 10px solid #333;
- border-radius: 50%;
- position: relative;
- background-color: #fff;
- box-shadow: 0 0 20px rgba(0,0,0,0.2);
- }
- .clock-face {
- position: relative;
- width: 100%;
- height: 100%;
- transform: translateY(-50%);
- }
- .number {
- position: absolute;
- width: 100%;
- height: 100%;
- text-align: center;
- font-size: 24px;
- font-weight: bold;
- font-family: Arial, sans-serif;
- color: #333;
- }
- .number span {
- display: block;
- padding-top: 10px;
- }
- .hand {
- position: absolute;
- bottom: 50%;
- left: 50%;
- transform-origin: bottom center;
- transform: translateX(-50%);
- border-top-left-radius: 10px;
- border-top-right-radius: 10px;
- z-index: 10;
- }
- .hour {
- width: 8px;
- height: 70px;
- background-color: #333;
- }
- .minute {
- width: 6px;
- height: 100px;
- background-color: #666;
- }
- .second {
- width: 2px;
- height: 120px;
- background-color: #f00;
- z-index: 11;
- }
- .center-dot {
- width: 16px;
- height: 16px;
- background-color: #333;
- border-radius: 50%;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- z-index: 12;
- }
- .ticks {
- position: absolute;
- width: 100%;
- height: 100%;
- }
- .tick {
- position: absolute;
- width: 4px;
- height: 10px;
- background-color: #333;
- left: 50%;
- top: 0;
- transform-origin: center 150px;
- }
- .long-tick {
- width: 6px;
- height: 15px;
- }
- </style>
- </head>
- <body>
- <div class="clock">
- <div class="clock-face">
- <div class="ticks" id="ticks"></div>
- <div class="number" style="transform: rotate(30deg);"><span>1</span></div>
- <div class="number" style="transform: rotate(60deg);"><span>2</span></div>
- <div class="number" style="transform: rotate(90deg);"><span>3</span></div>
- <div class="number" style="transform: rotate(120deg);"><span>4</span></div>
- <div class="number" style="transform: rotate(150deg);"><span>5</span></div>
- <div class="number" style="transform: rotate(180deg);"><span>6</span></div>
- <div class="number" style="transform: rotate(210deg);"><span>7</span></div>
- <div class="number" style="transform: rotate(240deg);"><span>8</span></div>
- <div class="number" style="transform: rotate(270deg);"><span>9</span></div>
- <div class="number" style="transform: rotate(300deg);"><span>10</span></div>
- <div class="number" style="transform: rotate(330deg);"><span>11</span></div>
- <div class="number" style="transform: rotate(0deg);"><span>12</span></div>
- <div class="hand hour" id="hourHand"></div>
- <div class="hand minute" id="minuteHand"></div>
- <div class="hand second" id="secondHand"></div>
- <div class="center-dot"></div>
- </div>
- </div>
- <script>
- // Create ticks for the clock
- const ticksContainer = document.getElementById('ticks');
- for (let i = 0; i < 60; i++) {
- const tick = document.createElement('div');
- tick.className = i % 5 === 0 ? 'tick long-tick' : 'tick';
- tick.style.transform = `rotate(${i * 6}deg)`;
- ticksContainer.appendChild(tick);
- }
- function updateClock() {
- const now = new Date();
- const seconds = now.getSeconds();
- const minutes = now.getMinutes();
- const hours = now.getHours();
- const secondDegrees = (seconds / 60) * 360;
- const minuteDegrees = ((minutes + seconds / 60) / 60) * 360;
- const hourDegrees = ((hours + minutes / 60) / 12) * 360;
- document.getElementById('secondHand').style.transform = `translateX(-50%) rotate(${secondDegrees}deg)`;
- document.getElementById('minuteHand').style.transform = `translateX(-50%) rotate(${minuteDegrees}deg)`;
- document.getElementById('hourHand').style.transform = `translateX(-50%) rotate(${hourDegrees}deg)`;
- }
- setInterval(updateClock, 1000);
- updateClock(); // Initial call to set the time immediately
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment