Elegant Timer - MeggiTools
Run
Toggle Theme
Share Link
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Elegant Timer</title> <style> body { font-family: 'Times New Roman', Times, serif; background: #f0f0f0; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .timer-container { background: #fff; border: 1px solid #ddd; border-radius: 10px; box-shadow: 0 0 15px rgba(0, 0, 0, 0.1); padding: 30px; text-align: center; max-width: 400px; width: 100%; } .timer { font-size: 3em; margin: 20px 0; color: #333; } .controls { display: flex; justify-content: space-around; } button { background: #007bff; border: none; border-radius: 5px; color: #fff; padding: 10px 20px; font-size: 1em; cursor: pointer; transition: background 0.3s; } button:hover { background: #0056b3; } button:disabled { background: #ccc; cursor: not-allowed; } </style> </head> <body> <div class="timer-container"> <h1>Elegant Timer</h1> <div class="timer" id="timer">00:00:00</div> <div class="controls"> <button id="start">Start</button> <button id="stop" disabled>Stop</button> <button id="reset" disabled>Reset</button> </div> </div> <script> let timerInterval; let elapsedTime = 0; const timerElement = document.getElementById('timer'); const startButton = document.getElementById('start'); const stopButton = document.getElementById('stop'); const resetButton = document.getElementById('reset'); function updateTimer() { const hours = String(Math.floor(elapsedTime / 3600)).padStart(2, '0'); const minutes = String(Math.floor((elapsedTime % 3600) / 60)).padStart(2, '0'); const seconds = String(elapsedTime % 60).padStart(2, '0'); timerElement.textContent = `${hours}:${minutes}:${seconds}`; } function startTimer() { startButton.disabled = true; stopButton.disabled = false; resetButton.disabled = true; timerInterval = setInterval(() => { elapsedTime++; updateTimer(); }, 1000); } function stopTimer() { clearInterval(timerInterval); startButton.disabled = false; stopButton.disabled = true; resetButton.disabled = false; } function resetTimer() { elapsedTime = 0; updateTimer(); resetButton.disabled = true; } startButton.addEventListener('click', startTimer); stopButton.addEventListener('click', stopTimer); resetButton.addEventListener('click', resetTimer); </script> </body> </html>