qq黄钻代码,QQ黄钻代码
7
2026-12-05
"移动开钻"通常指移动端(手机/H5)的抽奖转盘/开钻(开宝箱)类功能,下面给你一个完整的可直接运行的实现方案。

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">移动开钻</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: linear-gradient(135deg, #1a1a2e, #16213e);
font-family: -apple-system, sans-serif;
}
.wheel-box { position: relative; width: 320px; height: 320px; }
.wheel {
width: 100%; height: 100%;
border-radius: 50%;
transition: transform 5s cubic-bezier(0.25, 0.1, 0.25, 1);
transform: rotate(0deg);
background: conic-gradient(
#ff6b6b 0deg 45deg, #feca57 45deg 90deg,
#48dbfb 90deg 135deg, #1dd1a1 135deg 180deg,
#ff9ff3 180deg 225deg, #f368e0 225deg 270deg,
#54a0ff 270deg 315deg, #5f27cd 315deg 360deg
);
box-shadow: 0 0 30px rgba(255, 200, 0, 0.5);
}
/* 指针 */
.pointer {
position: absolute;
top: 50%; left: 50%;
transform: translate(-50%, -50%);
width: 60px; height: 60px;
background: #fff;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
color: #e74c3c;
font-size: 16px;
box-shadow: 0 0 15px rgba(255,255,255,0.6);
z-index: 10;
cursor: pointer;
user-select: none;
}
.pointer:active { transform: translate(-50%, -50%) scale(0.92); }
.pointer::after {
content: '';
position: absolute;
top: -18px;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 20px solid #fff;
}
</style>
</head>
<body>
<div class="wheel-box">
<div class="wheel" id="wheel"></div>
<div class="pointer" id="pointer">开钻</div>
</div>
</body>
</html>
(function () {
const wheel = document.getElementById('wheel');
const pointer = document.getElementById('pointer');
const PRIZES = [
{ name: '钻石×100', angle: 22.5 },
{ name: '钻石×50', angle: 67.5 },
{ name: '谢谢参与', angle: 112.5 },
{ name: '钻石×10', angle: 157.5 },
{ name: '钻石×200', angle: 202.5 },
{ name: '再来一次', angle: 247.5 },
{ name: '钻石×5', angle: 292.5 },
{ name: '钻石×500', angle: 337.5 },
];
let rotating = false;
let currentRotation = 0;
/**
* 模拟服务端抽奖接口
* 实际项目中替换为 fetch('/api/lottery')
*/
function requestLottery() {
return new Promise((resolve) => {
// 模拟接口延迟
setTimeout(() => {
const index = Math.floor(Math.random() * PRIZES.length);
resolve({ code: 0, index, prize: PRIZES[index].name });
}, 500);
});
}
/**
* 计算停止角度
* 让指针最终指向中奖扇区的中心
*/
function calcTargetRotation(index) {
const prizeAngle = PRIZES[index].angle; // 扇区中心角度(顺时针,从顶部起)
// 需要转过的角度 = 360 - 扇区角度 + 圈数*360
const base = 360 - prizeAngle;
const extraRounds = 8; // 至少转8圈
// 加一个微小偏移,避免每次同角度显得假
const offset = (Math.random() - 0.5) * 20;
return currentRotation + extraRounds * 360 + (base - (currentRotation % 360)) + offset;
}
async function spin() {
if (rotating) return;
rotating = true;
pointer.textContent = '抽奖中';
try {
const res = await requestLottery();
if (res.code !== 0) {
alert('抽奖失败,请重试');
return;
}
const targetRotation = calcTargetRotation(res.index);
wheel.style.transition = 'transform 5s cubic-bezier(0.25, 0.1, 0.25, 1)';
wheel.style.transform = `rotate(${targetRotation}deg)`;
currentRotation = targetRotation;
// 过渡结束
wheel.addEventListener('transitionend', function onEnd() {
wheel.removeEventListener('transitionend', onEnd);
rotating = false;
pointer.textContent = '开钻';
// 重置旋转角度到 0~360,防止数值无限增大
if (currentRotation > 3600) {
currentRotation = currentRotation % 360;
wheel.style.transition = 'none';
wheel.style.transform = `rotate(${currentRotation}deg)`;
}
alert('恭喜获得:' + res.prize);
}, { once: true });
} catch (e) {
rotating = false;
pointer.textContent = '开钻';
console.error(e);
}
}
pointer.addEventListener('click', spin);
})();
如果需要的是"开宝箱"动画,核心代码:
function openBox() {
const box = document.getElementById('box');
const prize = document.getElementById('prize');
const result = await fetch('/api/open').then(r => r.json());
// 抖动
box.classList.add('shaking');
setTimeout(() => {
box.classList.remove('shaking');
box.classList.add('opened'); // 触发开启动画(放大+淡出)
prize.textContent = result.prize;
prize.classList.add('show'); // 奖品弹入
}, 800);
}
@keyframes shake {
0%,100% { transform: rotate(0); }
25% { transform: rotate(-8deg) scale(1.05); }
75% { transform: rotate(8deg) scale(1.05); }
}
.shaking { animation: shake 0.15s infinite; }
.opened { transform: scale(1.5); opacity: 0; transition: all 0.5s; }
| 要点 | 说明 |
|---|---|
| 服务端抽奖 | 中奖结果必须由后端返回,前端只负责动画,防止篡改 |
| 扇区角度计算 | 转盘用 conic-gradient 每扇区 45°,指针在顶部,转到 360 - 扇区中心角度 |
| transitionend | 用事件而非 setTimeout 保证动画回调精准 |
| 圈数重置 | 累计角度过大时归零,避免整数溢出 |
| 防连点 | rotating 标记防止重复请求 |
| 移动端适配 | user-scalable=no + 点击事件用 touchstart 更跟手 |
// 更跟手的点击(避免 300ms 延迟)
pointer.addEventListener('touchstart', (e) => {
e.preventDefault();
spin();
}, { passive: false });
请告诉我更多细节,我可以给出更贴合你项目的代码:

发表评论
暂时没有评论,来抢沙发吧~