File size: 9,615 Bytes
36182e2 8843e20 36182e2 8843e20 36182e2 8843e20 36182e2 8843e20 a2859c9 8843e20 a2859c9 8843e20 a2859c9 8843e20 a2859c9 8843e20 a2859c9 8843e20 a2859c9 8843e20 a2859c9 8843e20 36182e2 8843e20 36182e2 8843e20 a2859c9 8843e20 a2859c9 8843e20 a2859c9 8843e20 36182e2 8843e20 36182e2 8843e20 a2859c9 8843e20 a2859c9 8843e20 36182e2 8843e20 36182e2 8843e20 a2859c9 8843e20 36182e2 8843e20 36182e2 8843e20 36182e2 8843e20 36182e2 8843e20 36182e2 8843e20 36182e2 8843e20 36182e2 8843e20 36182e2 8843e20 36182e2 8843e20 36182e2 8843e20 36182e2 8843e20 36182e2 8843e20 36182e2 8843e20 36182e2 8843e20 36182e2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Elegant Digital Clock</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&display=swap');
.clock-container {
font-family: 'Orbitron', sans-serif;
text-shadow: 0 0 10px rgba(0, 255, 255, 0.7);
transition: all 0.5s ease;
}
.clock-face {
box-shadow: 0 0 20px rgba(0, 255, 255, 0.5),
inset 0 0 10px rgba(0, 0, 0, 0.5);
backdrop-filter: blur(5px);
}
.time-segment {
transition: all 0.3s ease;
}
.time-segment:hover {
transform: scale(1.05);
text-shadow: 0 0 15px rgba(0, 255, 255, 1);
}
.date-display {
letter-spacing: 2px;
text-shadow: 0 0 5px rgba(255, 255, 255, 0.7);
}
.theme-btn {
transition: all 0.3s ease;
}
.theme-btn:hover {
transform: rotate(15deg) scale(1.1);
}
.glow {
animation: glow 2s infinite alternate;
}
@keyframes glow {
from {
box-shadow: 0 0 5px rgba(0, 255, 255, 0.5);
}
to {
box-shadow: 0 0 20px rgba(0, 255, 255, 0.8);
}
}
</style>
</head>
<body class="bg-gray-900 min-h-screen flex items-center justify-center p-4 transition-colors duration-500">
<div class="clock-container w-full max-w-md">
<div class="clock-face bg-gray-800 bg-opacity-70 rounded-2xl p-8 border border-cyan-400 border-opacity-30 relative overflow-hidden">
<!-- Theme toggle button -->
<button id="themeToggle" class="theme-btn absolute top-4 right-4 text-cyan-400 text-xl hover:text-cyan-300">
<i class="fas fa-moon"></i>
</button>
<!-- Time display -->
<div class="time-display flex justify-center items-center mb-6">
<div id="hours" class="time-segment text-6xl font-bold text-cyan-400 mr-2">00</div>
<div class="text-6xl font-bold text-cyan-400 opacity-70">:</div>
<div id="minutes" class="time-segment text-6xl font-bold text-cyan-400 mx-2">00</div>
<div class="text-6xl font-bold text-cyan-400 opacity-70">:</div>
<div id="seconds" class="time-segment text-6xl font-bold text-cyan-400 ml-2">00</div>
</div>
<!-- AM/PM indicator -->
<div id="ampm" class="text-xl font-semibold text-cyan-300 text-center mb-1">AM</div>
<!-- Date display -->
<div id="date" class="date-display text-lg text-gray-300 text-center mt-4"></div>
<!-- Additional features -->
<div class="flex justify-center mt-6 space-x-4">
<button id="formatToggle" class="glow bg-cyan-800 bg-opacity-50 hover:bg-opacity-70 text-cyan-300 px-4 py-2 rounded-full flex items-center">
<i class="fas fa-exchange-alt mr-2"></i> 24H/12H
</button>
<button id="stopwatchBtn" class="glow bg-cyan-800 bg-opacity-50 hover:bg-opacity-70 text-cyan-300 px-4 py-2 rounded-full flex items-center">
<i class="fas fa-stopwatch mr-2"></i> Stopwatch
</button>
</div>
</div>
<!-- Footer with greeting -->
<div id="greeting" class="text-center mt-6 text-xl text-gray-300"></div>
</div>
<script>
// DOM elements
const hoursElement = document.getElementById('hours');
const minutesElement = document.getElementById('minutes');
const secondsElement = document.getElementById('seconds');
const ampmElement = document.getElementById('ampm');
const dateElement = document.getElementById('date');
const greetingElement = document.getElementById('greeting');
const themeToggle = document.getElementById('themeToggle');
const formatToggle = document.getElementById('formatToggle');
const stopwatchBtn = document.getElementById('stopwatchBtn');
const body = document.body;
const clockFace = document.querySelector('.clock-face');
// State variables
let is24HourFormat = true;
let isDarkTheme = true;
let isStopwatchMode = false;
let stopwatchStartTime = 0;
let stopwatchInterval = null;
// Initialize clock
updateClock();
setInterval(updateClock, 1000);
// Theme toggle
themeToggle.addEventListener('click', () => {
isDarkTheme = !isDarkTheme;
if (isDarkTheme) {
body.classList.remove('bg-gray-100');
body.classList.add('bg-gray-900');
clockFace.classList.remove('bg-gray-200', 'text-gray-800');
clockFace.classList.add('bg-gray-800', 'text-cyan-400');
themeToggle.innerHTML = '<i class="fas fa-moon"></i>';
document.querySelectorAll('.glow').forEach(el => {
el.classList.remove('bg-gray-300', 'text-gray-800');
el.classList.add('bg-cyan-800', 'text-cyan-300');
});
} else {
body.classList.remove('bg-gray-900');
body.classList.add('bg-gray-100');
clockFace.classList.remove('bg-gray-800', 'text-cyan-400');
clockFace.classList.add('bg-gray-200', 'text-gray-800');
themeToggle.innerHTML = '<i class="fas fa-sun"></i>';
document.querySelectorAll('.glow').forEach(el => {
el.classList.remove('bg-cyan-800', 'text-cyan-300');
el.classList.add('bg-gray-300', 'text-gray-800');
});
}
});
// Format toggle
formatToggle.addEventListener('click', () => {
is24HourFormat = !is24HourFormat;
updateClock();
});
// Stopwatch toggle
stopwatchBtn.addEventListener('click', () => {
isStopwatchMode = !isStopwatchMode;
if (isStopwatchMode) {
stopwatchStartTime = Date.now();
stopwatchInterval = setInterval(updateStopwatch, 10);
stopwatchBtn.innerHTML = '<i class="fas fa-stop mr-2"></i> Stop';
} else {
clearInterval(stopwatchInterval);
stopwatchBtn.innerHTML = '<i class="fas fa-stopwatch mr-2"></i> Stopwatch';
setTimeout(updateClock, 100); // Return to normal clock
}
});
// Update clock function
function updateClock() {
if (isStopwatchMode) return;
const now = new Date();
let hours = now.getHours();
const minutes = now.getMinutes();
const seconds = now.getSeconds();
const ampm = hours >= 12 ? 'PM' : 'AM';
// Format hours based on 12/24 hour setting
if (!is24HourFormat) {
hours = hours % 12 || 12;
}
// Update time display
hoursElement.textContent = hours.toString().padStart(2, '0');
minutesElement.textContent = minutes.toString().padStart(2, '0');
secondsElement.textContent = seconds.toString().padStart(2, '0');
// Update AM/PM display
ampmElement.textContent = is24HourFormat ? '' : ampm;
// Update date
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
dateElement.textContent = now.toLocaleDateString(undefined, options);
// Update greeting
updateGreeting(hours);
}
// Update stopwatch function
function updateStopwatch() {
const elapsed = Date.now() - stopwatchStartTime;
const milliseconds = Math.floor(elapsed % 1000 / 10);
const seconds = Math.floor(elapsed / 1000) % 60;
const minutes = Math.floor(elapsed / (1000 * 60)) % 60;
const hours = Math.floor(elapsed / (1000 * 60 * 60));
hoursElement.textContent = hours.toString().padStart(2, '0');
minutesElement.textContent = minutes.toString().padStart(2, '0');
secondsElement.textContent = seconds.toString().padStart(2, '0');
ampmElement.textContent = milliseconds.toString().padStart(2, '0');
dateElement.textContent = 'Stopwatch';
}
// Update greeting based on time of day
function updateGreeting(hours) {
let greeting = '';
if (hours < 12) {
greeting = 'Good Morning!';
} else if (hours < 18) {
greeting = 'Good Afternoon!';
} else {
greeting = 'Good Evening!';
}
greetingElement.textContent = greeting;
}
</script>
</body>
</html> |