timer / index.html
djaborolouai's picture
Add 3 files
790fe48 verified
Raw History Blame Contribute Delete
7.58 kB
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chronomètre Élégant</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>
.glow-text {
text-shadow: 0 0 10px rgba(59, 130, 246, 0.7);
}
.btn-hover:hover {
transform: translateY(-2px);
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}
.btn-active:active {
transform: translateY(1px);
}
.timer-container {
perspective: 1000px;
}
.timer-display {
transform-style: preserve-3d;
transition: transform 0.5s;
}
</style>
</head>
<body class="bg-gradient-to-br from-gray-900 to-gray-800 min-h-screen flex items-center justify-center p-4">
<div class="timer-container text-center">
<h1 class="text-4xl md:text-5xl font-bold text-white mb-8 glow-text">Chronomètre</h1>
<div class="timer-display bg-gray-800 rounded-xl p-8 mb-10 shadow-2xl border border-gray-700">
<div class="text-6xl md:text-8xl font-mono font-bold text-blue-400">
<span id="hours">00</span>:<span id="minutes">00</span>:<span id="seconds">00</span>
<span class="text-4xl md:text-6xl" id="milliseconds">.00</span>
</div>
</div>
<div class="flex justify-center space-x-4 md:space-x-6">
<button id="startBtn" class="bg-green-600 hover:bg-green-700 text-white px-6 py-3 rounded-full text-lg font-semibold transition-all duration-300 btn-hover btn-active shadow-lg flex items-center">
<i class="fas fa-play mr-2"></i> Démarrer
</button>
<button id="stopBtn" class="bg-red-600 hover:bg-red-700 text-white px-6 py-3 rounded-full text-lg font-semibold transition-all duration-300 btn-hover btn-active shadow-lg flex items-center" disabled>
<i class="fas fa-stop mr-2"></i> Arrêter
</button>
<button id="resetBtn" class="bg-blue-600 hover:bg-blue-700 text-white px-6 py-3 rounded-full text-lg font-semibold transition-all duration-300 btn-hover btn-active shadow-lg flex items-center">
<i class="fas fa-redo mr-2"></i> Réinitialiser
</button>
</div>
<div class="mt-12 text-gray-400">
<p class="text-sm">Appuyez sur Démarrer pour commencer le chronomètre</p>
</div>
</div>
<script>
let startTime;
let elapsedTime = 0;
let timerInterval;
let isRunning = false;
const startBtn = document.getElementById('startBtn');
const stopBtn = document.getElementById('stopBtn');
const resetBtn = document.getElementById('resetBtn');
const hoursDisplay = document.getElementById('hours');
const minutesDisplay = document.getElementById('minutes');
const secondsDisplay = document.getElementById('seconds');
const millisecondsDisplay = document.getElementById('milliseconds');
function startTimer() {
if (!isRunning) {
startTime = Date.now() - elapsedTime;
timerInterval = setInterval(updateTimer, 10);
isRunning = true;
toggleButtons();
// Animation
document.querySelector('.timer-display').style.transform = 'rotateX(5deg)';
}
}
function stopTimer() {
if (isRunning) {
clearInterval(timerInterval);
elapsedTime = Date.now() - startTime;
isRunning = false;
toggleButtons();
// Animation
document.querySelector('.timer-display').style.transform = 'rotateX(0)';
}
}
function resetTimer() {
clearInterval(timerInterval);
elapsedTime = 0;
isRunning = false;
updateDisplay();
toggleButtons();
// Animation
document.querySelector('.timer-display').style.transform = 'rotateX(-5deg)';
setTimeout(() => {
document.querySelector('.timer-display').style.transform = 'rotateX(0)';
}, 300);
}
function updateTimer() {
const currentTime = Date.now();
elapsedTime = currentTime - startTime;
updateDisplay();
}
function updateDisplay() {
let totalMilliseconds = elapsedTime;
let totalSeconds = Math.floor(totalMilliseconds / 1000);
let totalMinutes = Math.floor(totalSeconds / 60);
let totalHours = Math.floor(totalMinutes / 60);
let milliseconds = Math.floor((totalMilliseconds % 1000) / 10);
let seconds = totalSeconds % 60;
let minutes = totalMinutes % 60;
let hours = totalHours % 24;
millisecondsDisplay.textContent = `.${milliseconds.toString().padStart(2, '0')}`;
secondsDisplay.textContent = seconds.toString().padStart(2, '0');
minutesDisplay.textContent = minutes.toString().padStart(2, '0');
hoursDisplay.textContent = hours.toString().padStart(2, '0');
}
function toggleButtons() {
startBtn.disabled = isRunning;
stopBtn.disabled = !isRunning;
if (isRunning) {
startBtn.classList.remove('bg-green-600', 'hover:bg-green-700');
startBtn.classList.add('bg-gray-500', 'cursor-not-allowed');
stopBtn.classList.remove('bg-gray-500', 'cursor-not-allowed');
stopBtn.classList.add('bg-red-600', 'hover:bg-red-700');
} else {
startBtn.classList.remove('bg-gray-500', 'cursor-not-allowed');
startBtn.classList.add('bg-green-600', 'hover:bg-green-700');
stopBtn.classList.remove('bg-red-600', 'hover:bg-red-700');
stopBtn.classList.add('bg-gray-500', 'cursor-not-allowed');
}
}
// Event listeners
startBtn.addEventListener('click', startTimer);
stopBtn.addEventListener('click', stopTimer);
resetBtn.addEventListener('click', resetTimer);
// Keyboard controls
document.addEventListener('keydown', (e) => {
if (e.code === 'Space') {
e.preventDefault();
if (isRunning) stopTimer();
else startTimer();
} else if (e.code === 'KeyR') {
resetTimer();
}
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=djaborolouai/timer" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>