抽奖转盘源码,带动画和音效

2026-11-17 0 295

文章摘要

这是一份炫酷动画抽奖转盘源码,包含完整HTML/CSS/JavaScript实现。转盘采用7个彩色小球环绕公转,中心为抽奖按钮,点击后转盘加速旋转并随机中奖,中奖小球高亮闪烁并触发粒子爆炸和音效,底部卡片栏展示中奖号码,无弹窗设计简洁流畅,适合活动抽奖场景使用。

抽奖转盘源码,带动画和音效

  1. <!doctype html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  6. <title>炫酷动画抽奖转盘|标签卡片中奖</title>
  7. <style>
  8.   * {
  9.     box-sizing: border-box;
  10.     margin: 0;
  11.     padding: 0;
  12.     user-select: none;
  13.     -webkit-tap-highlight-color: transparent;
  14.   }
  15.   body {
  16.     min-height: 100vh;
  17.     display: flex;
  18.     flex-direction: column;
  19.     align-items: center;
  20.     justify-content: center;
  21.     background: radial-gradient(circle at 30% 20%, #1f2a44 0%, #070b18 100%);
  22.     font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  23.     overflow: hidden;
  24.     gap:20px;
  25.   }
  26.   .stage {
  27.     position: relative;
  28.     width: 340px;
  29.     height: 340px;
  30.     display: flex;
  31.     align-items: center;
  32.     justify-content: center;
  33.   }
  34.   /* 外层装饰环 */
  35.   .ring-outer {
  36.     position: absolute;
  37.     width: 320px;
  38.     height: 320px;
  39.     border-radius: 50%;
  40.     border: 2px dashed rgba(120, 180, 255, 0.35);
  41.     animation: rotate 18s linear infinite;
  42.   }
  43.   .ring-inner {
  44.     position: absolute;
  45.     width: 260px;
  46.     height: 260px;
  47.     border-radius: 50%;
  48.     border: 1px solid rgba(255, 255, 255, 0.08);
  49.     box-shadow:
  50.       inset 0 0 40px rgba(72, 128, 255, 0.25),
  51.       0 0 40px rgba(72, 128, 255, 0.15);
  52.   }
  53.   .sweep {
  54.     position: absolute;
  55.     width: 320px;
  56.     height: 320px;
  57.     border-radius: 50%;
  58.     background: conic-gradient(
  59.       from 0deg,
  60.       transparent 0deg,
  61.       transparent 250deg,
  62.       rgba(255, 170, 60, 0.35) 340deg,
  63.       rgba(255, 220, 120, 0.55) 355deg,
  64.       transparent 360deg
  65.     );
  66.     animation: rotate 6s linear infinite;
  67.     mix-blend-mode: screen;
  68.     pointer-events: none;
  69.   }
  70.   .pointer {
  71.     position: absolute;
  72.     top: 10px;
  73.     left: 50%;
  74.     transform: translateX(-50%);
  75.     width: 0;
  76.     height: 0;
  77.     border-left: 14px solid transparent;
  78.     border-right: 14px solid transparent;
  79.     border-top: 22px solid #ff3b6b;
  80.     filter: drop-shadow(0 4px 10px rgba(255, 59, 107, 0.6));
  81.     z-index: 10;
  82.   }
  83.   /* 公转轨道 */
  84.   .orbit {
  85.     position: absolute;
  86.     width: 240px;
  87.     height: 240px;
  88.     border-radius: 50%;
  89.     animation: rotate linear infinite;
  90.     animation-play-state: paused;
  91.   }
  92.   .ball {
  93.     position: absolute;
  94.     top: 50%;
  95.     left: 50%;
  96.     width: 46px;
  97.     height: 46px;
  98.     margin-left: -23px;
  99.     margin-top: -23px;
  100.     border-radius: 50%;
  101.     color: #fff;
  102.     font-size: 20px;
  103.     font-weight: 700;
  104.     display: flex;
  105.     align-items: center;
  106.     justify-content: center;
  107.     cursor: pointer;
  108.     transition: all 0.3s;
  109.     /* 小球自身呼吸缩放发光动画 */
  110.     animation: ballBreathe 1.4s ease-in-out infinite;
  111.   }
  112.   /* 7个球不同颜色 */
  113.   .ball[data-index="1"]{background:radial-gradient(circle at 30% 30%,#ff8fa8,#ff2f5f 60%,#b21040);box-shadow:0 0 16px rgba(255,47,95,0.6);}
  114.   .ball[data-index="2"]{background:radial-gradient(circle at 30% 30%,#87d8ff,#0099ff 60%,#005cad);box-shadow:0 0 16px rgba(0,153,255,0.6);}
  115.   .ball[data-index="3"]{background:radial-gradient(circle at 30% 30%,#b8ff9c,#36d12e 60%,#1b8016);box-shadow:0 0 16px rgba(54,209,46,0.6);}
  116.   .ball[data-index="4"]{background:radial-gradient(circle at 30% 30%,#fff29c,#ffd322 60%,#b88c00);box-shadow:0 0 16px rgba(255,211,34,0.6);color:#222;}
  117.   .ball[data-index="5"]{background:radial-gradient(circle at 30% 30%,#e2b8ff,#b04dff 60%,#7c1fc9);box-shadow:0 0 16px rgba(176,77,255,0.6);}
  118.   .ball[data-index="6"]{background:radial-gradient(circle at 30% 30%,#ffc396,#ff7722 60%,#b34400);box-shadow:0 0 16px rgba(255,119,34,0.6);}
  119.   .ball[data-index="7"]{background:radial-gradient(circle at 30% 30%,#94f3e8,#00c9b0 60%,#007c6d);box-shadow:0 0 16px rgba(0,201,176,0.6);}
  120.   /* 中奖高亮 */
  121.   .ball.win {
  122.     background: radial-gradient(circle at 30% 30%, #ffe27a, #ffb400 60%, #d27a00) !important;
  123.     box-shadow: 0 0 30px rgba(255,190,50,1),0 0 70px rgba(255,160,0,0.7) !important;
  124.     animation: ballWinFlash 0.5s ease-in-out infinite alternate !important;
  125.   }
  126.   /* 中心抽奖按钮 */
  127.   .center {
  128.     position: absolute;
  129.     width: 110px;
  130.     height: 110px;
  131.     border-radius: 50%;
  132.     background: radial-gradient(circle at 35% 25%, #3f8cff, #1543d8 70%, #0a248f);
  133.     color: #fff;
  134.     font-size: 22px;
  135.     font-weight: 700;
  136.     letter-spacing: 2px;
  137.     display: flex;
  138.     align-items: center;
  139.     justify-content: center;
  140.     cursor: pointer;
  141.     z-index: 20;
  142.     box-shadow:
  143.       0 0 30px rgba(60, 130, 255, 0.55),
  144.       inset 0 -8px 14px rgba(0, 0, 0, 0.35),
  145.       inset 0 8px 14px rgba(160, 200, 255, 0.45);
  146.     transition: transform 0.15s ease;
  147.   }
  148.   .center:active { transform: scale(0.94); }
  149.   .center::before {
  150.     content:"";position:absolute;inset:-10px;border-radius:50%;
  151.     border:1px solid rgba(120,180,255,0.4);animation:rotate 5s linear infinite;
  152.   }
  153.   /* 粒子爆炸容器 */
  154.   #particleWrap{
  155.     position:absolute;width:100%;height:100%;pointer-events:none;overflow:hidden;z-index:15;
  156.   }
  157.   .particle{
  158.     position:absolute;border-radius:50%;
  159.   }
  160.   /* ====== 卡片广告栏式中奖提示(替代弹窗)====== */
  161.   .prize-bar{
  162.     width:320px;
  163.     padding:14px 20px;
  164.     border-radius:12px;
  165.     background:linear-gradient(90deg,#2c2058,#422b80);
  166.     border:1px solid #ffcc44;
  167.     box-shadow: 0 0 22px rgba(255,204,68,0.35);
  168.     color:#ffe89c;
  169.     font-size:18px;
  170.     text-align:center;
  171.     opacity:0;
  172.     transform: translateY(10px);
  173.     transition: all 0.35s ease;
  174.     pointer-events:none;
  175.   }
  176.   .prize-bar.show{
  177.     opacity:1;
  178.     transform: translateY(0);
  179.   }
  180.   .prize-tag{
  181.     display:inline-block;
  182.     background:#ffb400;
  183.     color:#111;
  184.     font-weight:bold;
  185.     padding:3px 12px;
  186.     border-radius:6px;
  187.     margin:0 8px;
  188.   }
  189.   @keyframes rotate { from{transform:rotate(0deg);} to{transform:rotate(360deg);} }
  190.   @keyframes ballBreathe {
  191.     0%,100%{ transform:translate(var(--tx),var(--ty)) scale(1); filter:brightness(1); }
  192.     50%{ transform:translate(var(--tx),var(--ty)) scale(1.15); filter:brightness(1.25); }
  193.   }
  194.   @keyframes ballWinFlash {
  195.     from{ transform:translate(var(--tx),var(--ty)) scale(1); }
  196.     to{ transform:translate(var(--tx),var(--ty)) scale(1.28); }
  197.   }
  198.   @keyframes particleFly {
  199.     0%{opacity:1;transform:translate(0,0) scale(1);}
  200.     100%{opacity:0;transform:translate(var(--px),var(--py)) scale(0);}
  201.   }
  202.   @media (max-width:360px){
  203.     .stage{width:300px;height:300px;}
  204.     .ring-outer{width:280px;height:280px;}
  205.     .sweep{width:280px;height:280px;}
  206.     .ring-inner{width:230px;height:230px;}
  207.     .orbit{width:210px;height:210px;}
  208.     .ball{width:40px;height:40px;margin-left:-20px;margin-top:-20px;font-size:18px;}
  209.     .center{width:96px;height:96px;font-size:20px;}
  210.     .prize-bar{width:280px;font-size:16px;}
  211.   }
  212. </style>
  213. </head>
  214. <body>
  215. <div class="stage">
  216.   <div class="ring-outer"></div>
  217.   <div class="ring-inner"></div>
  218.   <div class="sweep"></div>
  219.   <div class="pointer"></div>
  220.   <div id="particleWrap"></div>
  221.   <div class="orbit" id="orbit">
  222.     <div class="ball" data-index="1">1</div>
  223.     <div class="ball" data-index="2">2</div>
  224.     <div class="ball" data-index="3">3</div>
  225.     <div class="ball" data-index="4">4</div>
  226.     <div class="ball" data-index="5">5</div>
  227.     <div class="ball" data-index="6">6</div>
  228.     <div class="ball" data-index="7">7</div>
  229.   </div>
  230.   <div class="center" id="centerBtn">抽奖</div>
  231. </div>
  232. <!-- 广告栏卡片标签模式中奖展示,无弹窗 -->
  233. <div class="prize-bar" id="prizeBar">
  234.   &#127881;恭喜!中奖号码:<span class="prize-tag" id="prizeNum">--</span>
  235. </div>
  236. <audio id="winAudio" preload="auto" src="https://assets.mixkit.co/sfx/preview/mixkit-achievement-bell-600.mp3">
  237. <script>
  238. const orbit = document.getElementById("orbit");
  239. const balls = document.querySelectorAll(".ball");
  240. const centerBtn = document.getElementById("centerBtn");
  241. const particleWrap = document.getElementById("particleWrap");
  242. const winAudio = document.getElementById("winAudio");
  243. const prizeBar = document.getElementById("prizeBar");
  244. const prizeNum = document.getElementById("prizeNum");
  245. const BALL_COUNT = 7;
  246. const SEGMENT = 360 / BALL_COUNT;
  247. let isRunning = false;
  248. let isPaused = false;
  249. let currentAngle = 0;
  250. //初始化小球圆周位置,使用css变量给呼吸动画用
  251. function initBalls(){
  252.   balls.forEach((ball,i)=>{
  253.     const angle = SEGMENT*i;
  254.     const rad = (angle -90)*Math.PI/180;
  255.     const r =95;
  256.     const x = Math.cos(rad)*r;
  257.     const y = Math.sin(rad)*r;
  258.     ball.style.setProperty("--tx",x+"px");
  259.     ball.style.setProperty("--ty",y+"px");
  260.     ball.style.transform = `translate(${x}px,${y}px)`;
  261.     ball.dataset.angle = angle;
  262.   })
  263. }
  264. //粒子爆炸效果
  265. function createExplode(){
  266.   const count =40;
  267.   const colors =["#ffd040","#ff4e75","#40c8ff","#7bff6c","#c78bff"];
  268.   for(let i=0;i<count;i++){
  269.     const p = document.createElement("div");
  270.     p.className="particle";
  271.     const size = 4 + Math.random()*8;
  272.     p.style.width = size+"px";
  273.     p.style.height = size+"px";
  274.     p.style.background = colors[Math.floor(Math.random()*colors.length)];
  275.     const angle = Math.random()*Math.PI*2;
  276.     const dist = 60 + Math.random()*130;
  277.     p.style.setProperty("--px", Math.cos(angle)*dist +"px");
  278.     p.style.setProperty("--py", Math.sin(angle)*dist +"px");
  279.     p.style.left="50%";p.style.top="50%";
  280.     p.style.marginLeft = "-"+size/2+"px";
  281.     p.style.marginTop = "-"+size/2+"px";
  282.     p.style.animation = "particleFly 0.8s ease-out forwards";
  283.     particleWrap.appendChild(p);
  284.     setTimeout(()=>p.remove(),800);
  285.   }
  286. }
  287. // 点击小球:切换暂停/继续转动
  288. function togglePause(){
  289.   if(isRunning) return;
  290.   isPaused = !isPaused;
  291.   orbit.style.animationPlayState = isPaused ? "paused":"running";
  292. }
  293. function setOrbitSpeed(dur){
  294.   orbit.style.animation = `rotate ${dur}s linear infinite`;
  295.   orbit.style.animationPlayState = "running";
  296. }
  297. function wait(ms){return new Promise(res=>setTimeout(res,ms));}
  298. async function lottery(){
  299.   if(isRunning) return;
  300.   isRunning=true;
  301.   balls.forEach(b=>b.classList.remove("win"));
  302.   prizeBar.classList.remove("show");
  303.   const winIdx = Math.floor(Math.random()*BALL_COUNT);
  304.   setOrbitSpeed(1.1);
  305.   const extraTurn = 5 + Math.floor(Math.random()*3);
  306.   const winBallAngle = Number(balls[winIdx].dataset.angle);
  307.   const targetAngle = 360 - winBallAngle;
  308.   const stopTotal = 360*extraTurn + targetAngle;
  309.   orbit.style.transition = "transform 4.6s cubic-bezier(0.17,0.67,0.24,1)";
  310.   orbit.style.transform = `rotate(${currentAngle + stopTotal}deg)`;
  311.   await wait(4600);
  312.   currentAngle = (currentAngle + stopTotal) %360;
  313.   orbit.style.transition = "";
  314.   orbit.style.animationPlayState = "paused";
  315.   balls[winIdx].classList.add("win");
  316.   createExplode();
  317.   winAudio.currentTime=0;
  318.   winAudio.play().catch(e=>{});
  319.   // 卡片标签广告栏展示中奖,无弹窗
  320.   prizeNum.innerText = `${winIdx+1} 号`;
  321.   prizeBar.classList.add("show");
  322.   isRunning=false;
  323. }
  324. balls.forEach(b=>b.addEventListener("click",togglePause));
  325. centerBtn.addEventListener("click",lottery);
  326. //启动
  327. initBalls();
  328. setOrbitSpeed(6);
  329. orbit.style.animationPlayState="running";
  330. </script>
  331. </body>
  332. </html>
复制代码
收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

本站所有资源来源于网络,仅限用于学习研究;无任何技术支持!不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除内容。如果您喜欢,请支持正版。如有侵权请邮件与我们联系处理。

Img 1 16
下一篇:

已经没有下一篇了!

常见问题
  • 网盘有时候会因为名字 关键词导致失效 大家可以给管理员提供失效信息,我们会给大家适当积分进行奖励 我们会第一时间进行补充修正 感谢大家的配合 让我们共同努力 打造良好的资源分享平台
查看详情

相关文章

官方客服团队

为您解决烦忧 - 24小时在线 专业服务