網頁頁面用科技感和精簡,並有dark mode
- User
網頁頁面用科技感和精簡,並有dark mode
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
網頁頁面用科技感和精簡,並有dark mode
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
以下是一個使用 HTML、CSS 和 JavaScript 實現的倒數計時器,具有科技感和精簡設計,並且有暗黑模式(Dark Mode)功能:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>倒數計時器</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>倒數計時器</h1>
<input type="datetime-local" id="datetimeInput" class="input-field">
<div class="timer-display">
<span id="days">00</span><span class="timer-unit">天</span>
<span id="hours">00</span><span class="timer-unit">時</span>
<span id="minutes">00</span><span class="timer-unit">分</span>
<span id="seconds">00</span><span class="timer-unit">秒</span>
</div>
<div class="button-group">
<button id="startButton" class="button">開始</button>
<button id="pauseButton" class="button" disabled>暫停</button>
<button id="resetButton" class="button" disabled>重置</button>
<button id="darkModeButton" class="button">暗黑模式</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
/* style.css */
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
transition: background-color 0.3s ease;
}
.container {
max-width: 400px;
margin: 40px auto;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
transition: background-color 0.3s ease, box-shadow 0.3s ease;
}
.input-field {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: none;
border-radius: 5px;
font-size: 16px;
}
.timer-display {
font-size: 24px;
font-weight: bold;
margin-bottom: 20px;
}
.timer-unit {
font-size: 16px;
color: #666;
}
.button-group {
display: flex;
justify-content: space-between;
}
.button {
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
background-color: #4CAF50;
color: #fff;
transition: background-color 0.3s ease;
}
.button:hover {
background-color: #45a049;
}
#darkModeButton {
background-color: #333;
}
#darkModeButton:hover {
background-color: #444;
}
.dark-mode {
background-color: #333;
}
.dark-mode .container {
background-color: #444;
box-shadow: 0 0 10px rgba(0,0,0,0.5);
}
.dark-mode .input-field {
background-color: #555;
color: #fff;
}
.dark-mode .timer-display {
color: #fff;
}
.dark-mode .timer-unit {
color: #ccc;
}
.dark-mode .button {
background-color: #555;
}
.dark-mode .button:hover {
background-color: #666;
}
// script.js
let countdownInterval = null;
let targetDate = null;
const startButton = document.getElementById('startButton');
const pauseButton = document.getElementById('pauseButton');
const resetButton = document.getElementById('resetButton');
const darkModeButton = document.getElementById('darkModeButton');
const datetimeInput = document.getElementById('datetimeInput');
function updateDisplay() {
const currentDate = new Date();
const timeLeft = targetDate - currentDate;
if (timeLeft <= 0) {
clearInterval(countdownInterval);
alert('時間到!');
resetTimer();
return;
}
const days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);
document.getElementById('days').textContent = days.toString().padStart(2, '0');
document.getElementById('hours').textContent = hours.toString().padStart(2, '0');
document.getElementById('minutes').textContent = minutes.toString().padStart(2, '0');
document.getElementById('seconds').textContent = seconds.toString().padStart(2, '0');
}
function startTimer() {
targetDate = new Date(datetimeInput.value);
if (isNaN(targetDate)) {
alert('請選擇有效的日期和時間');
return;
}
countdownInterval = setInterval(updateDisplay, 1000);
startButton.disabled = true;
pauseButton.disabled = false;
resetButton.disabled = false;
updateDisplay();
}
function pauseTimer() {
clearInterval(countdownInterval);
countdownInterval = null;
pauseButton.disabled = true;
startButton.disabled = false;
}
function resetTimer() {
clearInterval(countdownInterval);
countdownInterval = null;
targetDate = null;
document.getElementById('days').textContent = '00';
document.getElementById('hours').textContent = '00';
document.getElementById('minutes').textContent = '00';
document.getElementById('seconds').textContent = '00';
startButton.disabled = false;
pauseButton.disabled = true;
resetButton.disabled = true;
datetimeInput.value = '';
}
function toggleDarkMode() {
document.body.classList.toggle('dark-mode');
}
// 按鈕事件監聽
startButton.addEventListener('click', startTimer);
pauseButton.addEventListener('click', pauseTimer);
resetButton.addEventListener('click', resetTimer);
darkModeButton.addEventListener('click', toggleDarkMode);
這個版本的倒數計時器具有以下特點:
你可以直接複製這個完整的 HTML、CSS 和 JavaScript 代碼到你的專案中,或者儲存為 .html、.css 和 .js 檔案直接在瀏覽器中打開。