<!DOCTYPE html>
<html lang="zh-CN">
<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=Noto+Sans+SC:wght@400;500;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
user-select: none;
}
body {
font-family: 'Noto Sans SC', sans-serif;
background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
color: #fff;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
perspective: 1000px;
overflow-x: hidden;
}
.container {
width: 100%;
max-width: 900px;
background: rgba(255, 255, 255, 0.1);
border-radius: 15px;
padding: 30px;
backdrop-filter: blur(12px);
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.25);
border: 1px solid rgba(255, 255, 255, 0.2);
text-align: center;
position: relative;
}
h1 {
font-size: 2.5rem;
margin-bottom: 25px;
color: #fff;
text-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
position: relative;
display: flex;
justify-content: center;
align-items: center;
gap: 15px;
}
h1:after {
content: "";
position: absolute;
bottom: -10px;
left: 50%;
transform: translateX(-50%);
width: 80%;
height: 3px;
background: linear-gradient(to right, transparent, #ff9800, transparent);
}
.subtitle {
font-size: 1.1rem;
opacity: 0.85;
margin-bottom: 25px;
}
.food-display {
width: 100%;
min-height: 180px;
display: flex;
justify-content: center;
align-items: center;
margin: 20px auto;
border-radius: 15px;
background: rgba(0, 0, 0, 0.2);
padding: 20px;
font-size: 3.5rem;
font-weight: bold;
color: #fff;
box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.2);
transition: all 0.3s ease;
border: 2px solid rgba(255, 255, 255, 0.15);
}
.food-display.active {
background: rgba(255, 255, 255, 0.15);
box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.15);
}
#food-name {
padding: 10px 20px;
border-radius: 10px;
transition: all 0.05s ease;
}
.result {
font-size: 4rem;
color: #ffeb3b;
text-shadow: 0 0 15px rgba(255, 235, 59, 0.7);
animation: scaleUp 0.5s forwards;
}
.control-panel {
display: flex;
justify-content: center;
gap: 20px;
margin: 30px 0;
flex-wrap: wrap;
}
.btn {
padding: 14px 30px;
border: none;
border-radius: 10px;
color: white;
font-size: 1.1rem;
font-weight: bold;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 10px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
border: 1px solid rgba(255, 255, 255, 0.2);
min-width: 180px;
}
.btn:hover {
transform: translateY(-3px) scale(1.05);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}
.btn:active {
transform: translateY(1px);
}
.btn:disabled {
background: linear-gradient(to right, #757575, #9e9e9e);
cursor: not-allowed;
transform: none;
box-shadow: none;
}
.start-btn {
background: linear-gradient(to right, #4CAF50, #8BC34A);
}
.pause-btn {
background: linear-gradient(to right, #ff9800, #ff5722);
}
.reset-btn {
background: linear-gradient(to right, #2196F3, #03A9F4);
}
.speed-indicator {
position: absolute;
top: 20px;
right: 20px;
padding: 8px 20px;
background: rgba(255, 87, 34, 0.8);
border-radius: 30px;
font-size: 1rem;
font-weight: bold;
border: 1px solid rgba(255, 255, 255, 0.2);
display: flex;
align-items: center;
gap: 8px;
}
.timer-display {
font-size: 1.3rem;
margin: 25px 0;
display: flex;
justify-content: center;
gap: 10px;
align-items: center;
font-weight: 500;
background: rgba(0, 0, 0, 0.15);
padding: 10px;
border-radius: 10px;
max-width: 500px;
margin: 25px auto;
}
.timer-value {
font-weight: bold;
color: #ff9800;
font-size: 1.6rem;
text-shadow: 0 0 10px rgba(255, 152, 0, 0.5);
}
.custom-foods {
margin-top: 25px;
padding: 20px;
background: rgba(255, 255, 255, 0.1);
border-radius: 15px;
border: 1px solid rgba(255, 255, 255, 0.15);
position: relative;
}
.section-title {
margin-bottom: 20px;
color: #ffeb3b;
display: flex;
justify-content: center;
align-items: center;
gap: 10px;
font-size: 1.4rem;
}
.food-tags {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 15px;
padding: 15px 0;
}
.food-tag {
padding: 12px 40px 12px 25px;
background: rgba(255, 152, 0, 0.2);
border-radius: 30px;
font-size: 1.1rem;
cursor: pointer;
transition: all 0.3s ease;
color: #fff;
border: 1px solid rgba(255, 152, 0, 0.5);
display: flex;
align-items: center;
position: relative;
overflow: hidden;
animation: slideIn 0.5s ease-out forwards;
transform: translateX(0);
opacity: 1;
min-width: 140px;
}
.food-tag:hover {
background: rgba(255, 152, 0, 0.3);
transform: translateY(-2px);
}
.food-tag.selected {
background: rgba(255, 235, 59, 0.3);
border: 1px solid #ffeb3b;
}
.delete-tag {
position: absolute;
top: 50%;
right: 12px;
transform: translateY(-50%);
display: inline-flex;
align-items: center;
justify-content: center;
width: 22px;
height: 22px;
border-radius: 50%;
background: rgba(244, 67, 54, 0.8);
color: white;
font-size: 0.9rem;
cursor: pointer;
transition: all 0.3s;
opacity: 0;
}
.food-tag:hover .delete-tag {
opacity: 1;
transform: translateY(-50%) scale(1.1);
}
.delete-tag:hover {
background: rgba(211, 47, 47, 1);
transform: translateY(-50%) scale(1.2);
}
.tag-action {
display: flex;
justify-content: center;
gap: 20px;
margin-top: 25px;
}
.tag-action-btn {
padding: 10px 20px;
border-radius: 30px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
display: flex;
align-items: center;
gap: 8px;
background: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
color: #fff;
font-size: 1rem;
}
.tag-action-btn:hover {
transform: translateY(-2px);
background: rgba(255, 255, 255, 0.2);
}
.add-food-area {
display: flex;
justify-content: center;
gap: 15px;
margin-top: 20px;
width: 100%;
max-width: 600px;
margin: 30px auto 0;
}
#add-food {
flex: 1;
padding: 15px 20px;
border-radius: 8px;
border: 1px solid #ff9800;
background: rgba(255,255,255,0.1);
color: #fff;
font-size: 1.1rem;
transition: all 0.3s;
}
#add-food:focus {
outline: none;
border-color: #ffeb3b;
box-shadow: 0 0 15px rgba(255, 235, 59, 0.5);
background: rgba(255,255,255,0.15);
}
#add-food::placeholder {
color: rgba(255, 255, 255, 0.6);
font-style: italic;
}
#add-btn {
padding: 15px 30px;
border-radius: 10px;
border: none;
background: linear-gradient(to right, #ff5722, #ff9800);
color: white;
font-weight: bold;
display: flex;
align-items: center;
gap: 10px;
cursor: pointer;
transition: all 0.3s;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}
#add-btn:hover {
transform: translateY(-3px);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}
.notification {
position: fixed;
bottom: 30px;
left: 50%;
transform: translateX(-50%);
padding: 15px 35px;
border-radius: 30px;
background: rgba(76, 175, 80, 0.9);
z-index: 1000;
animation: fadeIn 0.3s, fadeOut 0.3s 2s forwards;
box-shadow: 0 5px 20px rgba(0,0,0,0.3);
display: flex;
align-items: center;
gap: 15px;
font-size: 1.1rem;
}
/* 动画效果 */
@keyframes fadeIn {
from { opacity: 0; transform: translate(-50%, 20px); }
to { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes fadeOut {
from { opacity: 1; }
to { opacity: 0; transform: translate(-50%, 20px); }
}
@keyframes scaleUp {
0% { transform: scale(0.8); opacity: 0; }
100% { transform: scale(1); opacity: 1; }
}
@keyframes flash {
0% { opacity: 1; }
50% { opacity: 0.7; }
100% { opacity: 1; }
}
@keyframes tagDelete {
to { transform: scale(0); opacity: 0; margin: 0; padding: 0; height: 0; }
}
@keyframes slideIn {
from { transform: translateX(30px); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
@keyframes bounce {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.1); }
}
/* 响应式设计 */
@media (max-width: 768px) {
.container {
padding: 20px 15px;
}
h1 {
font-size: 2rem;
}
.food-display {
min-height: 150px;
font-size: 2.5rem;
}
.btn {
padding: 12px 20px;
font-size: 1rem;
min-width: 160px;
}
.food-tag {
padding: 10px 35px 10px 22px;
font-size: 1rem;
}
.add-food-area {
flex-direction: column;
}
.control-panel {
gap: 10px;
}
.tag-action {
flex-direction: column;
gap: 10px;
align-items: center;
}
.food-tags {
gap: 10px;
}
}
</style>
</head>
<body>
<div class="container">
<h1><i class="fas fa-utensils"></i>美食极速选择器</h1>
<div class="subtitle">超高速随机选择 - 0.05秒/次</div>
<div class="food-display">
<div id="food-name">点击开始选择</div>
</div>
<div class="speed-indicator">
<i class="fas fa-bolt"></i>极速模式
</div>
<div class="control-panel">
<button id="start-btn" class="btn start-btn">
<i class="fas fa-play"></i>开始选择
</button>
<button id="pause-btn" class="btn pause-btn" disabled>
<i class="fas fa-pause"></i>立即暂停
</button>
<button id="reset-btn" class="btn reset-btn">
<i class="fas fa-redo"></i>重新开始
</button>
</div>
<div class="timer-display">
<i class="fas fa-clock"></i>
<span>系统将在 <span class="timer-value" id="timer">5.00</span> 秒后自动暂停</span>
</div>
<div class="custom-foods">
<div class="section-title">
<i class="fas fa-tags"></i>美食管理
</div>
<div class="tag-action">
<button class="tag-action-btn select-all" id="select-all-btn">
<i class="fas fa-check-square"></i>全选
</button>
<button class="tag-action-btn remove-all" id="remove-all-btn">
<i class="fas fa-trash"></i>删除全部
</button>
</div>
<div class="food-tags" id="food-tags"></div>
<div class="add-food-area">
<input type="text" id="add-food" placeholder="添加新的美食...">
<button id="add-btn">
<i class="fas fa-plus"></i>添加美食
</button>
</div>
</div>
</div>
<script>
// 默认美食列表
const defaultFoods = [
"猪脚饭", "汉堡薯条", "麻辣烫", "烧腊饭", "黄焖鸡米饭",
"酸辣粉", "肠粉", "沙县小吃", "热干面", "重庆小面",
"兰州拉面", "凉皮", "生煎", "锅贴", "炒饭",
"冒菜", "鸭血粉丝汤", "胡辣汤", "砂锅粥", "螺蛳粉",
"水饺", "馄饨抄手", "披萨", "桂林米粉", "日本料理",
"韩国料理", "麻辣香锅", "沙拉轻食", "烩面", "刀削面",
"油泼面", "炸酱面", "米线", "土豆粉", "肉夹馍",
"羊肉汤", "盖浇饭", "卤肉饭", "烤肉饭", "驴肉火烧",
"火锅", "酸菜鱼", "烤串", "烤鸭", "炸鸡",
"寿司", "蟹黄包", "煎饼果子", "炒年糕"
];
// 当前选择状态
let isSelecting = false;
let interval;
let autoStopInterval;
let timer = null;
let timeLeft = 0;
let selectedFoods = [...defaultFoods];
let selectedTags = [];
// 页面加载完成后初始化
document.addEventListener('DOMContentLoaded', () => {
populateFoodTags();
// 绑定按钮事件
document.getElementById('start-btn').addEventListener('click', startSelection);
document.getElementById('pause-btn').addEventListener('click', pauseSelection);
document.getElementById('reset-btn').addEventListener('click', resetSelection);
document.getElementById('add-btn').addEventListener('click', addNewFood);
document.getElementById('add-food').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
addNewFood();
}
});
document.getElementById('remove-all-btn').addEventListener('click', removeAllTags);
document.getElementById('select-all-btn').addEventListener('click', selectAllTags);
});
// 生成美食标签
function populateFoodTags() {
const container = document.getElementById('food-tags');
container.innerHTML = '';
selectedFoods.forEach(food => {
const tag = document.createElement('div');
tag.classList.add('food-tag');
const text = document.createElement('span');
text.textContent = food;
tag.appendChild(text);
const deleteBtn = document.createElement('span');
deleteBtn.classList.add('delete-tag');
deleteBtn.innerHTML = '✕';
deleteBtn.addEventListener('click', (e) => {
e.stopPropagation();
deleteFoodTag(food, tag);
});
tag.appendChild(deleteBtn);
tag.dataset.food = food;
tag.addEventListener('click', function() {
this.classList.toggle('selected');
if (this.classList.contains('selected')) {
if (!selectedTags.includes(food)) {
selectedTags.push(food);
}
} else {
const index = selectedTags.indexOf(food);
if (index > -1) {
selectedTags.splice(index, 1);
}
}
});
container.appendChild(tag);
});
}
// 删除标签
function deleteFoodTag(food, tagElement) {
// 添加删除动画
tagElement.style.animation = 'tagDelete 0.3s forwards';
setTimeout(() => {
// 更新食物列表
const index = selectedFoods.indexOf(food);
if (index > -1) {
selectedFoods.splice(index, 1);
}
// 更新选中标签列表
const tagIndex = selectedTags.indexOf(food);
if (tagIndex > -1) {
selectedTags.splice(tagIndex, 1);
}
// 更新标签显示
populateFoodTags();
showNotification(`已删除: ${food}`);
}, 300);
}
// 随机选择美食
function getRandomFood() {
// 获取选中的标签
if (selectedTags.length > 0) {
return selectedTags[Math.floor(Math.random() * selectedTags.length)];
}
// 否则使用全部列表
return selectedFoods[Math.floor(Math.random() * selectedFoods.length)];
}
// 更新食物名称
function updateFoodName() {
const foodName = document.getElementById('food-name');
foodName.textContent = getRandomFood();
}
// 开始选择美食
function startSelection() {
if (isSelecting) return;
if (selectedFoods.length === 0) {
showNotification('请先添加至少一种食物!');
return;
}
isSelecting = true;
document.getElementById('start-btn').disabled = true;
document.getElementById('pause-btn').disabled = false;
document.querySelector('.food-display').classList.add('active');
// 超高速切换美食名称 (0.05秒/次)
interval = setInterval(updateFoodName, 50);
// 随机在1-10秒后自动暂停
timeLeft = Math.random() * 9 + 1;
document.getElementById('timer').textContent = timeLeft.toFixed(2);
// 更新计时器显示
timer = setInterval(() => {
timeLeft -= 0.05;
if (timeLeft <= 0) {
pauseSelection();
return;
}
document.getElementById('timer').textContent = timeLeft.toFixed(2);
}, 50);
autoStopInterval = setTimeout(() => {
pauseSelection();
}, timeLeft * 1000);
}
// 暂停选择
function pauseSelection() {
if (!isSelecting) return;
isSelecting = false;
clearInterval(interval);
clearInterval(timer);
clearTimeout(autoStopInterval);
document.getElementById('pause-btn').disabled = true;
document.getElementById('start-btn').disabled = false;
document.querySelector('.food-display').classList.remove('active');
// 停止计时器显示
document.getElementById('timer').textContent = '0.00';
// 显示最终选择结果
const foodName = document.getElementById('food-name');
foodName.innerHTML = `<span class="result">${foodName.textContent}</span>`;
}
// 重置选择器
function resetSelection() {
pauseSelection();
document.getElementById('food-name').innerHTML = '点击开始选择';
}
// 添加新食物
function addNewFood() {
const input = document.getElementById('add-food');
const newFood = input.value.trim();
if (newFood) {
if (selectedFoods.includes(newFood)) {
showNotification('此食物已经存在');
} else {
selectedFoods.push(newFood);
populateFoodTags();
input.value = '';
showNotification(`已添加: ${newFood}`);
// 输入框添加动画效果
input.style.animation = 'bounce 0.3s';
setTimeout(() => input.style.animation = '', 300);
}
} else {
input.focus();
}
}
// 删除所有标签
function removeAllTags() {
if (selectedFoods.length === 0) return;
if (confirm('确定要删除所有食物标签吗?')) {
selectedFoods = [];
selectedTags = [];
populateFoodTags();
showNotification('已删除所有食物标签');
}
}
// 全选标签
function selectAllTags() {
const tags = document.querySelectorAll('.food-tag');
tags.forEach(tag => {
tag.classList.add('selected');
if (!selectedTags.includes(tag.dataset.food)) {
selectedTags.push(tag.dataset.food);
}
});
}
// 显示通知消息
function showNotification(message) {
const existing = document.querySelector('.notification');
if (existing) existing.remove();
const notification = document.createElement('div');
notification.classList.add('notification');
notification.innerHTML = `<i class="fas fa-check-circle"></i> ${message}`;
document.body.appendChild(notification);
setTimeout(() => {
notification.remove();
}, 2300);
}
</script>
</body>
</html>
index.html