<!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>
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
min-height: 100vh;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
color: white;
overflow-x: hidden;
padding: 20px 0;
}
.container {
background-color: rgba(0, 0, 0, 0.7);
border-radius: 15px;
padding: 30px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
text-align: center;
width: 90%;
max-width: 1000px;
backdrop-filter: blur(10px);
margin-bottom: 20px;
}
h1 {
margin-top: 0;
font-size: 2.5em;
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
}
.pool-section {
margin-bottom: 30px;
}
.pool-container {
background: rgba(0, 0, 0, 0.4);
border-radius: 10px;
padding: 15px;
margin-top: 15px;
}
.pool-title {
font-size: 1.3em;
margin-bottom: 10px;
color: #ffcc00;
font-weight: bold;
}
.pool-items {
display: flex;
flex-wrap: wrap;
gap: 10px;
justify-content: center;
min-height: 60px;
}
.pool-item {
background: linear-gradient(45deg, #00c6ff, #0072ff);
width: 40px;
height: 40px;
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.2em;
font-weight: bold;
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
cursor: pointer;
transition: all 0.3s;
}
.pool-item:hover {
transform: scale(1.1);
box-shadow: 0 0 15px rgba(0, 198, 255, 0.7);
}
.pool-item.selected {
background: linear-gradient(45deg, #00ff00, #009900);
transform: scale(1.1);
box-shadow: 0 0 20px rgba(0, 255, 0, 0.7);
}
.pool-item.used {
opacity: 0.5;
background: linear-gradient(45deg, #888, #555);
cursor: not-allowed;
}
.draw-section {
margin: 30px 0;
}
.groups-container {
display: flex;
flex-direction: column;
gap: 20px;
margin: 30px 0;
}
.group {
display: flex;
flex-direction: column;
gap: 10px;
}
.group-row {
display: flex;
justify-content: center;
gap: 20px;
}
.result-box {
width: 80px;
height: 80px;
background: linear-gradient(45deg, #ff0084, #33001b);
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
font-size: 2.5em;
font-weight: bold;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
position: relative;
overflow: hidden;
transition: all 0.3s;
cursor: pointer;
}
.result-box.winner {
background: linear-gradient(45deg, #00ff00, #009900);
transform: scale(1.1);
box-shadow: 0 0 20px rgba(0, 255, 0, 0.7);
}
.result-box::before {
content: '';
position: absolute;
top: -50%;
left: -50%;
width: 200%;
height: 200%;
background: linear-gradient(
to bottom right,
rgba(255, 255, 255, 0.3),
rgba(255, 255, 255, 0)
);
transform: rotate(30deg);
animation: shine 3s infinite;
}
@keyframes shine {
0% {
transform: rotate(30deg) translate(-30%, -30%);
}
100% {
transform: rotate(30deg) translate(30%, 30%);
}
}
button {
background: linear-gradient(45deg, #00c6ff, #0072ff);
color: white;
border: none;
padding: 12px 25px;
font-size: 1.1em;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
outline: none;
margin: 10px 5px;
min-width: 150px;
}
button:hover {
transform: translateY(-3px);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}
button:active {
transform: translateY(1px);
}
button:disabled {
background: linear-gradient(45deg, #666, #444);
cursor: not-allowed;
transform: none;
box-shadow: none;
}
.confetti {
position: absolute;
width: 10px;
height: 10px;
background-color: #f00;
opacity: 0;
}
@keyframes rollIn {
0% {
transform: scale(0) rotate(-180deg);
opacity: 0;
}
100% {
transform: scale(1) rotate(0);
opacity: 1;
}
}
.roll-in {
animation: rollIn 0.5s ease-out forwards;
}
@keyframes winnerPulse {
0% {
transform: scale(1);
box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}
50% {
transform: scale(1.1);
box-shadow: 0 0 25px rgba(0, 255, 0, 0.9);
}
100% {
transform: scale(1);
box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}
}
.winner-pulse {
animation: winnerPulse 1.5s infinite;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 10px;
justify-content: center;
margin-top: 20px;
}
.result-display {
font-size: 2em;
font-weight: bold;
color: #00ff00;
margin: 20px 0;
min-height: 1.5em;
}
.group-title {
font-size: 1.2em;
margin-bottom: 10px;
color: #00c6ff;
font-weight: bold;
}
.winner-select {
margin-top: 10px;
font-size: 0.9em;
color: #ccc;
}
@keyframes numberRoll {
0% { transform: translateY(-20px); opacity: 0; }
100% { transform: translateY(0); opacity: 1; }
}
.number-roll {
animation: numberRoll 0.3s ease-out;
}
.instructions {
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
padding: 15px;
margin: 20px 0;
text-align: left;
font-size: 0.9em;
}
.instructions h3 {
margin-top: 0;
color: #00c6ff;
}
.instructions ol {
padding-left: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>完整随机抽奖系统</h1>
<div class="instructions">
<h3>使用说明:</h3>
<ol>
<li>初始抽奖池包含1-26数字,点击"开始抽取"从池中随机抽取6个数字</li>
<li>抽取的数字分成三组,每组点击选择一个获胜数字</li>
<li>获胜数字会返回抽奖池,可以继续抽取</li>
<li>已使用的数字会变灰不可选</li>
</ol>
</div>
<div class="pool-section">
<div class="pool-title">初始抽奖池 (1-26)</div>
<div class="pool-container">
<div class="pool-items" id="initialPool"></div>
</div>
</div>
<div class="draw-section">
<button id="drawButton">开始抽取</button>
<div class="result-display" id="drawResult"></div>
</div>
<div class="groups-container" id="groupsContainer" style="display: none;">
<div class="group">
<div class="group-title">第一组</div>
<div class="group-row">
<div class="result-box" id="result1">?</div>
<div class="result-box" id="result2">?</div>
</div>
<div class="winner-select">点击选择获胜数字</div>
</div>
<div class="group">
<div class="group-title">第二组</div>
<div class="group-row">
<div class="result-box" id="result3">?</div>
<div class="result-box" id="result4">?</div>
</div>
<div class="winner-select">点击选择获胜数字</div>
</div>
<div class="group">
<div class="group-title">第三组</div>
<div class="group-row">
<div class="result-box" id="result5">?</div>
<div class="result-box" id="result6">?</div>
</div>
<div class="winner-select">点击选择获胜数字</div>
</div>
</div>
<div class="pool-section">
<div class="pool-title">获胜数字池</div>
<div class="pool-container">
<div class="pool-items" id="winnerPool"></div>
</div>
</div>
<div class="controls">
<button id="returnWinnersButton" disabled>将获胜数字返回抽奖池</button>
<button id="resetButton">重置全部</button>
</div>
</div>
<script>
// 初始化数据
let allNumbers = Array.from({length: 26}, (_, i) => i + 1);
let availableNumbers = [...allNumbers];
let usedNumbers = [];
let currentDraw = [];
let winners = [];
// 初始化页面
function initializePage() {
renderInitialPool();
document.getElementById('groupsContainer').style.display = 'none';
document.getElementById('drawResult').textContent = '';
document.getElementById('returnWinnersButton').disabled = true;
}
// 渲染初始抽奖池
function renderInitialPool() {
const poolElement = document.getElementById('initialPool');
poolElement.innerHTML = '';
allNumbers.forEach(num => {
const item = document.createElement('div');
item.className = 'pool-item';
item.textContent = num;
if (usedNumbers.includes(num)) {
item.classList.add('used');
} else {
item.addEventListener('click', () => toggleSelectNumber(num, item));
}
poolElement.appendChild(item);
});
}
// 渲染获胜数字池
function renderWinnerPool() {
const poolElement = document.getElementById('winnerPool');
poolElement.innerHTML = '';
winners.forEach(num => {
const item = document.createElement('div');
item.className = 'pool-item selected';
item.textContent = num;
poolElement.appendChild(item);
});
}
// 切换数字选择状态
function toggleSelectNumber(num, element) {
element.classList.toggle('selected');
}
// 获取选中的数字
function getSelectedNumbers() {
const selectedElements = document.querySelectorAll('#initialPool .pool-item.selected:not(.used)');
return Array.from(selectedElements).map(el => parseInt(el.textContent));
}
// 开始抽取
document.getElementById('drawButton').addEventListener('click', function() {
if (availableNumbers.length < 6) {
alert('抽奖池中剩余数字不足6个,请重置或返回获胜数字到抽奖池!');
return;
}
// 从可用数字中随机抽取6个
const shuffled = [...availableNumbers].sort(() => 0.5 - Math.random());
currentDraw = shuffled.slice(0, 6);
// 从可用数字中移除已抽取的数字
currentDraw.forEach(num => {
const index = availableNumbers.indexOf(num);
if (index !== -1) {
availableNumbers.splice(index, 1);
usedNumbers.push(num);
}
});
// 显示抽取结果
document.getElementById('drawResult').textContent = `已抽取: ${currentDraw.join(', ')}`;
document.getElementById('drawResult').classList.add('number-roll');
// 显示分组
showGroups(currentDraw);
// 重新渲染抽奖池
renderInitialPool();
// 禁用按钮
this.disabled = true;
// 触发重绘动画
setTimeout(() => {
document.getElementById('drawResult').classList.remove('number-roll');
}, 300);
});
// 显示分组
function showGroups(numbers) {
const groupsContainer = document.getElementById('groupsContainer');
groupsContainer.style.display = 'flex';
// 清空之前的选择
winners = [];
// 打乱顺序后分成三组
const shuffled = [...numbers].sort(() => 0.5 - Math.random());
const groups = [
[shuffled[0], shuffled[1]],
[shuffled[2], shuffled[3]],
[shuffled[4], shuffled[5]]
];
// 显示数字
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 2; j++) {
const box = document.getElementById(`result${i * 2 + j + 1}`);
box.textContent = groups[i][j];
box.classList.remove('winner', 'winner-pulse');
// 添加点击事件
box.onclick = function() {
// 清除同组的其他选择
const groupStart = i * 2;
document.getElementById(`result${groupStart + 1}`).classList.remove('winner', 'winner-pulse');
document.getElementById(`result${groupStart + 2}`).classList.remove('winner', 'winner-pulse');
// 标记当前选择的为获胜者
this.classList.add('winner', 'winner-pulse');
// 保存获胜数字
winners[i] = parseInt(this.textContent);
// 如果有3个获胜者,启用返回按钮
if (winners.filter(w => w).length === 3) {
document.getElementById('returnWinnersButton').disabled = false;
}
};
}
}
}
// 将获胜数字返回抽奖池
document.getElementById('returnWinnersButton').addEventListener('click', function() {
if (winners.length === 0 || winners.filter(w => w).length < 3) {
alert('请为每组选择一个获胜数字!');
return;
}
// 将获胜数字返回可用数字池
winners.forEach(num => {
if (num && usedNumbers.includes(num)) {
const index = usedNumbers.indexOf(num);
usedNumbers.splice(index, 1);
availableNumbers.push(num);
}
});
// 添加到获胜数字池显示
renderWinnerPool();
// 重置状态
winners = [];
document.getElementById('groupsContainer').style.display = 'none';
document.getElementById('drawResult').textContent = '获胜数字已返回抽奖池';
document.getElementById('drawButton').disabled = false;
this.disabled = true;
// 重新渲染抽奖池
renderInitialPool();
// 庆祝效果
createConfetti();
});
// 重置全部
document.getElementById('resetButton').addEventListener('click', function() {
availableNumbers = [...allNumbers];
usedNumbers = [];
currentDraw = [];
winners = [];
initializePage();
renderWinnerPool();
document.getElementById('drawButton').disabled = false;
});
// 创建庆祝效果
function createConfetti() {
const colors = ['#ff0000', '#00ff00', '#0000ff', '#ffff00', '#ff00ff', '#00ffff'];
for (let i = 0; i < 150; i++) {
const confetti = document.createElement('div');
confetti.className = 'confetti';
confetti.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)];
confetti.style.left = Math.random() * 100 + 'vw';
confetti.style.top = -10 + 'px';
confetti.style.transform = `rotate(${Math.random() * 360}deg)`;
confetti.style.width = Math.random() * 10 + 5 + 'px';
confetti.style.height = Math.random() * 10 + 5 + 'px';
document.body.appendChild(confetti);
const animationDuration = Math.random() * 3 + 2;
confetti.style.animation = `
drop ${animationDuration}s linear forwards,
fade ${animationDuration}s linear forwards
`;
// 随机运动路径
const keyframes = `
@keyframes drop {
0% {
top: -10px;
left: ${Math.random() * 100}vw;
opacity: 1;
}
100% {
top: 100vh;
left: ${Math.random() * 100}vw;
opacity: 0;
}
}
@keyframes fade {
0% { opacity: 1; }
80% { opacity: 1; }
100% { opacity: 0; }
}
`;
const style = document.createElement('style');
style.innerHTML = keyframes;
document.head.appendChild(style);
// 动画结束后移除元素
setTimeout(() => {
confetti.remove();
style.remove();
}, animationDuration * 1000);
}
}
// 初始化页面
initializePage();
</script>
</body>
</html>
—— 本文来自火龙信奥(义乌睿码科技):义乌青少年信息学奥赛与编程教育平台,专注 CSP-J/S、NOIP、GESP 竞赛培训,线上线下融合教学,助力编程升学。网址:hlcoding.com