<div class="container"> <h1>Chronometer</h1> <div class="display" id="display">00:00:00</div> <div class="controls"> <button class="start" id="startBtn">Start</button> <button class="stop" id="stopBtn" disabled>Stop</button> <button class="reset" id="resetBtn">Reset</button> </div> </div>
* { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; min-height: 100vh; display: flex; justify-content: center; align-items: center; background: linear-gradient(135deg, #D1E231 0%, #a8b828 100%); } .container { background: white; padding: 3rem 4rem; border-radius: 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2); text-align: center; min-width: 400px; } h1 { color: #333; font-size: 1.8rem; margin-bottom: 2rem; font-weight: 600; } .display { font-size: 4rem; font-weight: 300; color: #2c3e50; margin-bottom: 2.5rem; font-variant-numeric: tabular-nums; letter-spacing: 0.05em; } .controls { display: flex; gap: 1rem; justify-content: center; } button { padding: 0.9rem 2rem; font-size: 1rem; border: none; border-radius: 8px; cursor: pointer; font-weight: 500; transition: all 0.3s ease; text-transform: uppercase; letter-spacing: 0.05em; } .start { background: linear-gradient(135deg, #D1E231 0%, #a8b828 100%); color: #2c3e50; } .start:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(209, 226, 49, 0.4); } .stop { background: #e74c3c; color: white; } .stop:hover { background: #c0392b; transform: translateY(-2px); box-shadow: 0 5px 15px rgba(231, 76, 60, 0.4); } .reset { background: #95a5a6; color: white; } .reset:hover { background: #7f8c8d; transform: translateY(-2px); box-shadow: 0 5px 15px rgba(149, 165, 166, 0.4); } button:active { transform: translateY(0); } button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
let startTime = 0; let elapsedTime = 0; let timerInterval = null; const display = document.getElementById('display'); const startBtn = document.getElementById('startBtn'); const stopBtn = document.getElementById('stopBtn'); const resetBtn = document.getElementById('resetBtn'); function formatTime(ms) { const totalSeconds = Math.floor(ms / 1000); const hours = Math.floor(totalSeconds / 3600); const minutes = Math.floor((totalSeconds % 3600) / 60); const seconds = totalSeconds % 60; return `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`; } function updateDisplay() { const currentTime = Date.now(); elapsedTime = currentTime - startTime; display.textContent = formatTime(elapsedTime); } function start() { startTime = Date.now() - elapsedTime; timerInterval = setInterval(updateDisplay, 100); startBtn.disabled = true; stopBtn.disabled = false; } function stop() { clearInterval(timerInterval); startBtn.disabled = false; stopBtn.disabled = true; } function reset() { clearInterval(timerInterval); startTime = 0; elapsedTime = 0; display.textContent = '00:00:00'; startBtn.disabled = false; stopBtn.disabled = true; } startBtn.addEventListener('click', start); stopBtn.addEventListener('click', stop); resetBtn.addEventListener('click', reset);
Login to leave a comment
No comments yet. Be the first!
No comments yet. Be the first!