手搓一个随机选餐器
仅供娱乐
代码部分
<!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>
:root {
--primary-color: #00ff88;
--secondary-color: #2196f3;
}
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
margin: 0;
background: linear-gradient(-45deg, #0f0f1f, #1a1a2f, #2a1a2f);
background-size: 400% 400%;
animation: gradientBG 15s ease infinite;
font-family: 'Segoe UI', system-ui, sans-serif;
color: white;
overflow: hidden;
}
@keyframes gradientBG {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
#container {
position: relative;
text-align: center;
padding: 2rem 3rem;
background: rgba(255, 255, 255, 0.05);
border-radius: 20px;
backdrop-filter: blur(10px);
box-shadow: 0 0 30px rgba(0, 255, 136, 0.2);
z-index: 1;
border: 1px solid rgba(255, 255, 255, 0.1);
transition: transform 0.3s;
}
#container:hover {
transform: translateY(-5px);
}
h1 {
font-size: 2.5rem;
margin: 0 0 2rem;
background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
-webkit-background-clip: text;
background-clip: text;
color: transparent;
text-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
}
#display {
font-size: 2.5rem;
margin: 2rem;
padding: 1.5rem 3rem;
background: rgba(255, 255, 255, 0.05);
border-radius: 15px;
position: relative;
border: 2px solid transparent;
background-clip: padding-box;
transition: 0.3s;
}
#display::before {
content: '';
position: absolute;
top: -2px;
left: -2px;
right: -2px;
bottom: -2px;
background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
border-radius: inherit;
z-index: -1;
animation: borderFlow 3s linear infinite;
opacity: 0;
transition: opacity 0.3s;
}
.rolling#display::before {
opacity: 1;
}
@keyframes borderFlow {
0% { background-position: 0% 50%; }
100% { background-position: 200% 50%; }
}
button {
padding: 1rem 2.5rem;
font-size: 1.2rem;
background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
border: none;
border-radius: 50px;
color: #000;
cursor: pointer;
position: relative;
overflow: hidden;
transition: 0.3s;
font-weight: bold;
text-transform: uppercase;
letter-spacing: 1px;
}
button:hover {
transform: scale(1.05);
box-shadow: 0 0 30px rgba(0, 255, 136, 0.4);
}
button::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(
90deg,
transparent,
rgba(255, 255, 255, 0.3),
transparent
);
transition: 0.5s;
}
button:hover::before {
left: 100%;
}
.glow {
position: fixed;
width: 200px;
height: 200px;
background: radial-gradient(circle, rgba(0,255,136,0.3) 0%, transparent 70%);
filter: blur(60px);
z-index: 0;
}
.result {
animation: resultPop 0.5s;
color: var(--primary-color);
text-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
}
@keyframes resultPop {
0% { transform: scale(1); }
50% { transform: scale(1.2); }
100% { transform: scale(1); }
}
.particles {
position: fixed;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 0;
}
</style>
</head>
<body>
<div class="glow" style="top:20%; left:30%"></div>
<div class="glow" style="top:60%; left:70%"></div>
<div class="particles"></div>
<div id="container">
<h1>今天吃什么?</h1>
<div id="display">点击开始</div>
<button id="controlBtn">开始</button>
</div>
<script>
const meals = [
'🍔 汉堡套餐',
'🍜 牛肉面',
'🥟 饺子',
'🍕 披萨',
'🥗 沙拉',
'🍚 炒饭',
'🍲 火锅',
'🍣 寿司',
'🍗 炸鸡',
'🥪 三明治',
'🍜 米粉',
'🥩 烤肉'
];
let isRolling = false;
let intervalId = null;
const display = document.getElementById('display');
const controlBtn = document.getElementById('controlBtn');
function startRolling() {
isRolling = true;
controlBtn.textContent = '停止';
display.classList.add('rolling');
display.classList.remove('result');
intervalId = setInterval(() => {
const randomIndex = Math.floor(Math.random() * meals.length);
display.textContent = meals[randomIndex];
}, 50);
}
function stopRolling() {
isRolling = false;
clearInterval(intervalId);
controlBtn.textContent = '开始';
display.classList.remove('rolling');
display.classList.add('result');
}
controlBtn.addEventListener('click', () => {
if (isRolling) {
stopRolling();
} else {
startRolling();
}
});
// 添加粒子效果
function createParticles() {
const particles = document.querySelector('.particles');
for (let i = 0; i < 50; i++) {
const particle = document.createElement('div');
particle.style.cssText = `
position: absolute;
width: ${Math.random() * 5 + 2}px;
height: ${Math.random() * 5 + 2}px;
background: rgba(0, 255, 136, ${Math.random() * 0.5});
border-radius: 50%;
animation: float ${Math.random() * 5 + 5}s infinite linear;
left: ${Math.random() * 100}%;
top: ${Math.random() * 100}%;
`;
particles.appendChild(particle);
}
}
// 初始化粒子
createParticles();
// 添加动态样式
const style = document.createElement('style');
style.textContent = `
@keyframes float {
0% { transform: translateY(0) rotate(0deg); }
100% { transform: translateY(-100vh) rotate(360deg); }
}
@keyframes confettiFall {
0% { transform: translateY(0) rotate(0deg); }
100% { transform: translateY(100vh) rotate(720deg); }
}
`;
document.head.appendChild(style);
</script>
</body>
</html>
本文来自博客园,作者:厚礼蝎,转载请注明原文链接:https://www.cnblogs.com/guangdelw/p/18747133

浙公网安备 33010602011771号