Files
o.nmgjg.com.cn/index/kxdjs.html

246 lines
7.3 KiB
HTML
Executable File

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>奇妙的倒计时</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Arial', sans-serif;
}
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #000;
color: #fff;
overflow: hidden;
padding: 20px;
position: relative;
}
.toggle-container {
position: absolute;
top: 20px;
right: 20px;
display: flex;
align-items: center;
background: rgba(30, 30, 30, 0.9);
padding: 10px 15px;
border-radius: 25px;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
z-index: 100;
}
.toggle-text {
margin-right: 10px;
font-size: 0.9rem;
color: #ccc;
}
.toggle-switch {
position: relative;
display: inline-block;
width: 50px;
height: 24px;
}
.toggle-switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #333;
transition: .4s;
border-radius: 24px;
}
.slider:before {
position: absolute;
content: "";
height: 16px;
width: 16px;
left: 4px;
bottom: 4px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: #4da6ff;
}
input:checked + .slider:before {
transform: translateX(26px);
}
h1 {
font-size: 4rem;
margin-bottom: 60px;
text-transform: uppercase;
letter-spacing: 4px;
color: #fff;
text-align: center;
}
.timer {
font-size: 5.5rem;
font-weight: bold;
letter-spacing: 5px;
font-family: 'Courier New', monospace;
color: #4df;
padding: 20px;
border: 2px solid #333;
border-radius: 15px;
background: rgba(20, 20, 20, 0.9);
box-shadow: 0 0 40px rgba(255, 255, 255, 0.1);
width: 100%;
max-width: 800px;
text-align: center;
}
.milliseconds {
font-size: 0.6em;
font-family: 'Courier New', monospace;
display: inline-block;
width: 160px;
text-align: left;
color: #f84;
}
@media (max-width: 900px) {
h1 { font-size: 3rem; }
.timer { font-size: 4rem; }
}
@media (max-width: 600px) {
h1 { font-size: 2.2rem; }
.timer { font-size: 2.8rem; letter-spacing: 2px; }
.toggle-container {
top: 10px;
right: 10px;
padding: 8px 12px;
}
.toggle-text {
font-size: 0.8rem;
}
}
@media (max-width: 400px) {
h1 { font-size: 1.8rem; margin-bottom: 40px; }
.timer { font-size: 2.2rem; }
}
</style>
</head>
<body>
<div class="toggle-container">
<!-- <span class="toggle-text">心脏骤停?</span> -->
<label class="toggle-switch">
<input type="checkbox" id="toggle">
<span class="slider"></span>
</label>
</div>
<h1 id="title">距离开学还有</h1>
<div class="timer" id="timer">00:00:00:000</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const timerElement = document.getElementById('timer');
const titleElement = document.getElementById('title');
const toggleElement = document.getElementById('toggle');
const firstTarget = new Date('2025-09-01T00:00:00');
const secondTarget = new Date('2026-02-07T00:00:00');
const examTarget = new Date('2026-06-07T00:00:00');
let currentTarget = firstTarget;
let useExamTarget = false;
function updateTimer() {
const now = new Date();
let targetDate;
if (useExamTarget) {
targetDate = examTarget;
} else {
targetDate = now < firstTarget ? firstTarget : secondTarget;
}
if (targetDate !== currentTarget) {
currentTarget = targetDate;
updateTitle();
}
let diff = targetDate - now;
if (diff < 0) {
if (useExamTarget) {
timerElement.textContent = '00:00:00:000';
titleElement.textContent = '熬出头力!';
} else if (targetDate === secondTarget) {
timerElement.textContent = '00:00:00:000';
titleElement.textContent = '又放假力!';
}
return;
}
const hours = Math.floor(diff / (1000 * 60 * 60));
diff %= (1000 * 60 * 60);
const minutes = Math.floor(diff / (1000 * 60));
diff %= (1000 * 60);
const seconds = Math.floor(diff / 1000);
const milliseconds = diff % 1000;
timerElement.innerHTML =
`${padZero(hours)}:${padZero(minutes)}:${padZero(seconds)}:<span class="milliseconds">${padMilliseconds(milliseconds)}</span>`;
}
function updateTitle() {
if (useExamTarget) {
titleElement.textContent = '距离高考还有';
} else if (currentTarget === firstTarget) {
titleElement.textContent = '距离开学还有';
} else {
titleElement.textContent = '距离放假还有';
}
}
function padZero(num) {
return num.toString().padStart(2, '0');
}
function padMilliseconds(ms) {
return ms.toString().padStart(3, '0');
}
toggleElement.addEventListener('change', function() {
useExamTarget = this.checked;
updateTitle();
updateTimer();
});
updateTimer();
setInterval(updateTimer, 10);
});
</script>
</body>
</html>