網頁頁面用科技感和精簡,並有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.
好的,這是一個具備科技感、精簡風格以及 Dark Mode 切換功能的倒數計時器。
我們將會使用 CSS 變數 (--variable-name) 來管理顏色,這樣在切換 Dark Mode 時只需要改變這些變數的值即可。
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>科技感倒數計時器</title>
<link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&family=Roboto+Mono:wght@400;700&display=swap" rel="stylesheet">
<style>
/* CSS 變數定義 */
:root {
/* Light Mode Defaults */
--bg-color: #f0f2f5;
--text-color: #333;
--container-bg: #ffffff;
--border-color: #ddd;
--accent-color: #007bff; /* Bright blue for light mode */
--glow-color: rgba(0, 123, 255, 0.4);
--button-start-bg: #28a745;
--button-pause-bg: #ffc107;
--button-reset-bg: #dc3545;
--button-text-color: #ffffff;
--button-hover-transform: translateY(-2px);
--button-hover-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
--toggle-bg: #f8f9fa;
--toggle-text: #333;
}
/* Dark Mode */
body.dark-mode {
--bg-color: #1a1a2e; /* Deep dark blue */
--text-color: #e0e0e0;
--container-bg: #2d2a4a; /* Slightly lighter dark blue */
--border-color: #4a4a6e;
--accent-color: #00e676; /* Neon green for dark mode */
--glow-color: rgba(0, 230, 118, 0.6);
--button-start-bg: #00b894; /* Tealish green */
--button-pause-bg: #fdcb6e; /* Warm yellow */
--button-reset-bg: #ff7675; /* Soft red */
--button-text-color: #2d2a4a; /* Dark text for light buttons */
--button-hover-transform: translateY(-2px);
--button-hover-shadow: 0 4px 15px rgba(0, 230, 118, 0.3); /* Glow for dark mode buttons */
--toggle-bg: #4a4a6e;
--toggle-text: #e0e0e0;
}
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background-color: var(--bg-color);
color: var(--text-color);
font-family: 'Roboto Mono', monospace; /* Techy, minimalist font */
transition: background-color 0.5s ease, color 0.5s ease;
-webkit-font-smoothing: antialiased; /* Better font rendering */
-moz-osx-font-smoothing: grayscale;
}
.toggle-container {
position: absolute;
top: 20px;
right: 20px;
}
#darkModeToggle {
background-color: var(--toggle-bg);
color: var(--toggle-text);
border: 1px solid var(--border-color);
padding: 8px 15px;
border-radius: 5px;
cursor: pointer;
font-size: 0.9rem;
transition: all 0.3s ease;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
#darkModeToggle:hover {
background-color: var(--accent-color);
color: var(--button-text-color);
border-color: var(--accent-color);
}
.timer-container {
background-color: var(--container-bg);
padding: 40px;
border-radius: 12px;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.15);
border: 1px solid var(--border-color);
display: flex;
flex-direction: column;
align-items: center;
max-width: 90%;
width: 500px;
box-sizing: border-box;
transition: background-color 0.5s ease, border-color 0.5s ease, box-shadow 0.5s ease;
}
.time-input {
width: 100%;
padding: 12px;
margin-bottom: 25px;
border: 1px solid var(--border-color);
border-radius: 6px;
font-size: 1.1rem;
background-color: transparent;
color: var(--text-color);
outline: none;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
transition: border-color 0.3s ease, box-shadow 0.3s ease;
-webkit-appearance: none; /* Remove default styling for some browsers */
-moz-appearance: none;
}
.time-input:focus {
border-color: var(--accent-color);
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 8px var(--glow-color);
}
/* Styling for datetime-local picker icon in WebKit browsers */
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
filter: var(--text-color) == #e0e0e0 ? invert(1) : invert(0); /* Adjust icon color based on text color */
cursor: pointer;
opacity: 0.8;
transition: opacity 0.3s ease;
}
input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover {
opacity: 1;
}
.timer-display {
font-family: 'Orbitron', sans-serif; /* Futuristic font for numbers */
font-size: 3.8rem;
font-weight: bold;
margin: 20px 0;
color: var(--accent-color);
text-shadow: 0 0 15px var(--glow-color), 0 0 30px var(--glow-color);
letter-spacing: 2px;
display: flex;
align-items: baseline;
flex-wrap: wrap; /* Allow wrapping on smaller screens */
justify-content: center;
line-height: 1.2;
}
.timer-unit {
font-family: 'Roboto Mono', monospace;
font-size: 0.9rem;
color: var(--text-color);
margin-left: 8px;
margin-right: 20px;
opacity: 0.8;
transition: color 0.5s ease, opacity 0.5s ease;
}
/* Ensure the last unit doesn't have right margin */
.timer-display .timer-unit:last-child {
margin-right: 0;
}
.buttons {
margin-top: 25px;
display: flex;
gap: 15px;
flex-wrap: wrap; /* Allow wrapping on smaller screens */
justify-content: center;
}
button {
padding: 12px 25px;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 1rem;
font-weight: bold;
transition: all 0.3s ease;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
outline: none;
min-width: 100px;
}
button:hover:not(:disabled) {
transform: var(--button-hover-transform);
box-shadow: var(--button-hover-shadow);
}
button:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
#startButton {
background-color: var(--button-start-bg);
color: var(--button-text-color);
}
#pauseButton {
background-color: var(--button-pause-bg);
color: var(--button-text-color);
}
#resetButton {
background-color: var(--button-reset-bg);
color: var(--button-text-color);
}
/* Responsive adjustments */
@media (max-width: 600px) {
.timer-container {
padding: 25px;
}
.timer-display {
font-size: 2.5rem;
}
.timer-unit {
font-size: 0.8rem;
margin-right: 10px;
}
.buttons {
flex-direction: column;
gap: 10px;
width: 100%;
}
button {
width: 100%;
}
.toggle-container {
top: 10px;
right: 10px;
}
}
</style>
</head>
<body>
<div class="toggle-container">
<button id="darkModeToggle">切換模式</button>
</div>
<div class="timer-container">
<input type="datetime-local" id="datetimeInput" class="time-input">
<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="buttons">
<button id="startButton">開始</button>
<button id="pauseButton" disabled>暫停</button>
<button id="resetButton" disabled>重置</button>
</div>
</div>
<script>
let countdownInterval = null;
let targetDate = null; // Store the original target date
let remainingTimeAtPause = 0; // Store remaining time when paused
const startButton = document.getElementById('startButton');
const pauseButton = document.getElementById('pauseButton');
const resetButton = document.getElementById('resetButton');
const datetimeInput = document.getElementById('datetimeInput');
const darkModeToggle = document.getElementById('darkModeToggle');
// Function to update the countdown display
function updateDisplay() {
let timeLeft;
if (countdownInterval === null && remainingTimeAtPause > 0) {
// If paused, use the remaining time
timeLeft = remainingTimeAtPause;
} else {
// Otherwise, calculate from targetDate
const currentDate = new Date();
timeLeft = targetDate - currentDate;
}
if (timeLeft <= 0) {
clearInterval(countdownInterval);
countdownInterval = null;
alert('時間到!');
resetTimer(); // Reset after completion
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 to start the timer
function startTimer() {
if (countdownInterval) return; // Prevent multiple intervals
if (targetDate === null) { // First time starting or after reset
const selectedDateTime = datetimeInput.value;
if (!selectedDateTime) {
alert('請選擇有效的日期和時間!');
return;
}
targetDate = new Date(selectedDateTime);
// Check if target date is in the past
if (targetDate <= new Date()) {
alert('請選擇未來的日期和時間!');
datetimeInput.value = ''; // Clear input
return;
}
} else if (remainingTimeAtPause > 0) {
// Resume from pause: adjust targetDate based on remaining time
targetDate = new Date(new Date().getTime() + remainingTimeAtPause);
remainingTimeAtPause = 0; // Clear paused time
}
countdownInterval = setInterval(updateDisplay, 1000);
startButton.disabled = true;
pauseButton.disabled = false;
resetButton.disabled = false;
datetimeInput.disabled = true; // Disable input while running
updateDisplay(); // Call immediately to show correct time
}
// Function to pause the timer
function pauseTimer() {
if (!countdownInterval) return;
clearInterval(countdownInterval);
countdownInterval = null;
// Calculate remaining time at pause
remainingTimeAtPause = targetDate - new Date();
pauseButton.disabled = true;
startButton.disabled = false;
}
// Function to reset the timer
function resetTimer() {
clearInterval(countdownInterval);
countdownInterval = null;
targetDate = null;
remainingTimeAtPause = 0;
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 = ''; // Clear input field
datetimeInput.disabled = false; // Enable input
}
// Dark Mode Toggle Logic
function toggleDarkMode() {
document.body.classList.toggle('dark-mode');
const isDarkMode = document.body.classList.contains('dark-mode');
localStorage.setItem('darkMode', isDarkMode); // Save preference
darkModeToggle.textContent = isDarkMode ? 'Light Mode' : 'Dark Mode';
}
// Apply dark mode on load if preferred
document.addEventListener('DOMContentLoaded', () => {
const savedDarkMode = localStorage.getItem('darkMode');
if (savedDarkMode === 'true') {
document.body.classList.add('dark-mode');
darkModeToggle.textContent = 'Light Mode';
} else {
darkModeToggle.textContent = 'Dark Mode';
}
});
// Event Listeners
startButton.addEventListener('click', startTimer);
pauseButton.addEventListener('click', pauseTimer);
resetButton.addEventListener('click', resetTimer);
darkModeToggle.addEventListener('click', toggleDarkMode);
</script>
</body>
</html>
Orbitron 和 Roboto Mono。Orbitron 是一種非常未來感和科技感的字體,常用於倒數數字。Roboto Mono 則提供精簡、等寬的感覺,適合一般文字和單位。:root 和 .dark-mode) 定義了一套完整的淺色模式和深色模式顏色。#1a1a2e, #2d2a4a) 搭配霓虹綠 (#00e676) 作為強調色,營造科技氛圍。text-shadow 屬性,配合 var(--glow-color) 產生霓虹光暈效果,這是科技感的重要視覺元素。display: flex, justify-content: center, align-items: center)。border: 1px solid var(--border-color)) 而非厚重的陰影。datetime-local 輸入框的箭頭/日曆圖示也嘗試根據模式調整顏色(僅對 WebKit 瀏覽器有效,因為這個控件很難被完全客製化)。<body> 上的 dark-mode class。dark-mode class 覆蓋預設的 CSS 變數,從而改變所有相關元素的顏色。localStorage 儲存使用者的偏好,這樣在下次載入頁面時會自動應用上次選擇的模式。transition,使得模式切換或按鈕互動時的視覺變化更加平滑流暢。@media 查詢,在小螢幕設備上調整字體大小、內邊距、按鈕布局,確保在手機上也有良好的顯示效果。.html 檔案 (例如:countdown.html)。