请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

老师请问下这种抽奖怎么做的?可以说下思路么

图片描述

前端先做一会儿转的特效再发异步请求?还是后端延迟处理?不然这个转的特效怎么计算

正在回答 回答被采纳积分+3

1回答

接灰的电子产品 2025-06-27 17:25:40

给你个例子,资金体会一下

<!DOCTYPE html>

<html lang="zh">

<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;

display: flex;

justify-content: center;

align-items: center;

height: 100vh;

margin: 0;

background-color: #f4f4f4;

}

.lottery-container {

display: grid;

grid-template-columns: repeat(3, 100px);

grid-template-rows: repeat(3, 100px);

gap: 5px;

cursor: pointer;

}

.lottery-cell {

width: 100px;

height: 100px;

background-color: #ccc;

display: flex;

justify-content: center;

align-items: center;

font-size: 16px;

color: #fff;

border-radius: 10px;

transition: background-color 0.3s;

}

.highlight {

background-color: #ffcc00;

}

#prize-details {

display: none;

padding: 20px;

background-color: #fff;

border-radius: 10px;

box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);

width: 300px;

text-align: center;

}

#prize-details h2 {

margin-bottom: 20px;

}

#prize-details button {

padding: 10px 20px;

background-color: #4CAF50;

color: white;

border: none;

border-radius: 5px;

cursor: pointer;

}

#prize-details button:hover {

background-color: #45a049;

}

</style>

</head>

<body>

<div class="lottery-container">

<div class="lottery-cell" id="cell-0">奖品1</div>

<div class="lottery-cell" id="cell-1">奖品2</div>

<div class="lottery-cell" id="cell-2">奖品3</div>

<div class="lottery-cell" id="cell-3">奖品4</div>

<div class="lottery-cell" id="cell-4">点击开始</div>

<div class="lottery-cell" id="cell-5">奖品5</div>

<div class="lottery-cell" id="cell-6">奖品6</div>

<div class="lottery-cell" id="cell-7">奖品7</div>

<div class="lottery-cell" id="cell-8">奖品8</div>

</div>

<div id="prize-details">

<h2>恭喜!您获得了奖品5</h2>

<p>详细描述:这是一个非常棒的奖品!</p>

<button onclick="closePrizeDetails()">关闭</button>

</div>

<script>

const lotteryCells = document.querySelectorAll('.lottery-cell');

const prizeDetails = document.getElementById('prize-details');

let timer;

let currentHighlight = 0;

let prizeIndex = 4; // 最终停在奖品5的位置

// 顺时针依次高亮的顺序

const highlightOrder = [1, 2, 5, 8, 7, 6, 3, 0];

function highlightCells() {

let highlightCount = 0;

let highlightInterval = setInterval(() => {

// 清除之前的高亮

lotteryCells[highlightOrder[highlightCount]].classList.remove('highlight');

highlightCount++;

if (highlightCount === highlightOrder.length) {

clearInterval(highlightInterval);

stopLottery();

} else {

// 逐个顺时针高亮

lotteryCells[highlightOrder[highlightCount]].classList.add('highlight');

}

}, 300); // 每个格子高亮时间为300ms,速度加快

}

function stopLottery() {

// 停止在一个格子上

lotteryCells[prizeIndex].classList.add('highlight');

setTimeout(() => {

showPrizeDetails();

}, 500);

}

function showPrizeDetails() {

prizeDetails.style.display = 'block';

}

function closePrizeDetails() {

prizeDetails.style.display = 'none';

}

// 点击中间格子开始抽奖

document.getElementById('cell-4').addEventListener('click', () => {

lotteryCells[4].textContent = "抽奖中...";

highlightCells();

});

</script>

</body>

</html>

1 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
SpringBoot 3 + Flutter3 实战低代码运营管理
  • 参与学习       101    人
  • 解答问题       21    个

全栈|全流程|跨端|动态化部署|自动化测试,多领域全能型人才必修

了解课程
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号