update global css, add countdown and timer
This commit is contained in:
parent
c52aa334ca
commit
10022e6d93
8 changed files with 339 additions and 0 deletions
28
countdown/index.html
Normal file
28
countdown/index.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="shortcut icon" href="https://rimgo.pussthecat.org/RFbdMMB.png" type="image/x-icon">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<title>zy's Countdown</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="main">
|
||||
<a href="/timer">Stopwatch</a>
|
||||
<label for="hours-input">Hours</label><input id="hours-input" type="number" placeholder="0"/>
|
||||
<label for="minutes-input">Minutes</label><input id="minutes-input" type="number" placeholder="0"/>
|
||||
<label for="seconds-input">Seconds</label><input id="seconds-input" type="number" placeholder="0"/>
|
||||
<span id="time">00:00:00:00</span>
|
||||
<button id="start">Start</button>
|
||||
<button id="reset">Reset</button>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
71
countdown/index.js
Normal file
71
countdown/index.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
const time = document.getElementById('time');
|
||||
const start = document.getElementById('start');
|
||||
const reset = document.getElementById('reset');
|
||||
const hoursInput = document.getElementById('hours-input');
|
||||
const minutesInput = document.getElementById('minutes-input');
|
||||
const secondsInput = document.getElementById('seconds-input');
|
||||
const sound = new Audio('/assets/pipe.mp3');
|
||||
|
||||
let timer = null;
|
||||
let isActive = false;
|
||||
let remainingTime = 0;
|
||||
|
||||
function formatTime(duration) {
|
||||
const milliseconds = Math.floor((duration % 1000) / 10);
|
||||
const seconds = Math.floor((duration / 1000) % 60);
|
||||
const minutes = Math.floor((duration / 1000 / 60) % 60);
|
||||
const hours = Math.floor(duration / 1000 / 60 / 60);
|
||||
return `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}:${String(milliseconds).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
start.addEventListener('click', () => {
|
||||
if (!isActive) {
|
||||
const hours = parseInt(hoursInput.value, 10) || 0;
|
||||
const minutes = parseInt(minutesInput.value, 10) || 0;
|
||||
const seconds = parseInt(secondsInput.value, 10) || 0;
|
||||
|
||||
if (hours < 0 || minutes < 0 || minutes > 59 || seconds < 0 || seconds > 59) {
|
||||
alert("Please enter valid time values.");
|
||||
return;
|
||||
}
|
||||
|
||||
remainingTime = (hours * 3600 + minutes * 60 + seconds) * 1000;
|
||||
|
||||
if (remainingTime <= 0) {
|
||||
alert("Please enter a valid time duration.");
|
||||
return;
|
||||
}
|
||||
|
||||
isActive = true;
|
||||
start.innerHTML = "Stop";
|
||||
|
||||
timer = setInterval(() => {
|
||||
remainingTime -= 10;
|
||||
if (remainingTime <= 0) {
|
||||
clearInterval(timer);
|
||||
sound.play();
|
||||
time.textContent = "00:00:00:00";
|
||||
isActive = false;
|
||||
start.innerHTML = "Start";
|
||||
} else {
|
||||
time.textContent = formatTime(remainingTime);
|
||||
}
|
||||
}, 10);
|
||||
} else {
|
||||
isActive = false;
|
||||
clearInterval(timer);
|
||||
start.innerHTML = "Start";
|
||||
}
|
||||
});
|
||||
|
||||
reset.addEventListener('click', () => {
|
||||
isActive = false;
|
||||
clearInterval(timer);
|
||||
timer = null;
|
||||
remainingTime = 0;
|
||||
time.textContent = "00:00:00:00";
|
||||
start.innerHTML = "Start";
|
||||
hoursInput.value = "";
|
||||
minutesInput.value = "";
|
||||
secondsInput.value = "";
|
||||
});
|
76
countdown/style.css
Normal file
76
countdown/style.css
Normal file
|
@ -0,0 +1,76 @@
|
|||
@import url(/global.css);
|
||||
|
||||
input {
|
||||
width: 70px;
|
||||
padding: 12px;
|
||||
margin: 10px 5px;
|
||||
border: 2px solid #5a5a5a;
|
||||
border-radius: 6px;
|
||||
background-color: #2a2a2a;
|
||||
color: #ffffff;
|
||||
font-size: 16px;
|
||||
text-align: center;
|
||||
transition: border-color 0.3s ease, box-shadow 0.3s ease;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
border-color: #4caf50;
|
||||
box-shadow: 0 0 5px #4caf50;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 12px 20px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
background-color: #4caf50;
|
||||
color: #ffffff;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
margin: 10px 5px;
|
||||
font-weight: bold;
|
||||
transition: background-color 0.3s ease, transform 0.2s ease;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #45a049;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
button:active {
|
||||
background-color: #3e8e41;
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
div.main {
|
||||
padding: 50px;
|
||||
background-color: #3a3a3a;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
|
||||
text-align: center;
|
||||
max-width: 600px;
|
||||
margin: 50px auto;
|
||||
}
|
||||
|
||||
span#time {
|
||||
font-size: 36px;
|
||||
font-weight: bold;
|
||||
display: block;
|
||||
margin: 25px 0;
|
||||
color: #f5f5f5;
|
||||
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
a {
|
||||
bottom: 20px;
|
||||
left: 20px;
|
||||
position: absolute;
|
||||
color: #b3b3b3;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
transition: color 0.3s ease;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #ffffff;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue