使用html实现抽奖程序,没有后台,如果需要后续写个后台可以配置,没有过多的介绍,看代码吧

<!DOCTYPE html>
<html lang="zh">
<head><meta charset="UTF-8"><title>婚礼抽奖</title><style>html, body {height: 100%;margin: 0;padding: 0;/* 这里改成红色渐变 */background: radial-gradient(circle at 60% 10%, #ffb2b2 0%, #d7000f 100%);overflow: hidden;}body {font-family: '微软雅黑','Segoe UI',Arial,sans-serif;}/* 跑马灯样式 */.marquee-bar-wrap {position: fixed;left:0; top: 0;width:100vw;height: 46px;background: linear-gradient(90deg,#ffdce7 0%,#fffbe7 60%,#ffdce7 100%);border-bottom: 2px solid #ffb6c1;z-index: 3000;box-shadow: 0 4px 20px #ffe4e950;display: flex;align-items: center;overflow: hidden;pointer-events: none;}.marquee-bar-content {position: absolute;white-space: nowrap;font-size: 1.45em;color: #e75480;font-weight: bold;letter-spacing: 2px;text-shadow: 0 2px 10px #fff0f7f0;left: 100vw;animation: marqueeMove 16s linear infinite;}@keyframes marqueeMove {from { left: 100vw; }to   { left: -100vw;}}.container {position: absolute;left: 50%; top: 50%;transform: translate(-50%,-50%);width: 1200px;height: 700px;background: rgba(255,255,255,0.93);border-radius: 36px;box-shadow: 0 10px 80px #f8bbd0bb;overflow: hidden;z-index: 1;}.title-area {position: absolute;width: 100%;top: 0;left: 0;text-align: center;z-index: 10;pointer-events: none;}h1 {margin: 36px 0 10px 0;font-size: 2.8em;color: #d72660;letter-spacing: 3px;font-weight: bold;}.subtitle {font-size: 1.3em;color: #a93a48;margin-bottom: 10px;letter-spacing: 2px;}.draw-btn {position: absolute;left: 50%; top: 620px;transform: translateX(-50%);font-size: 1.35em;background: linear-gradient(90deg, #ffb6c1 0%, #d72660 100%);border: none;color: #fff;padding: 18px 58px;border-radius: 32px;cursor: pointer;box-shadow: 0 4px 25px #d7266040;font-weight: bold;letter-spacing: 2px;outline: none;opacity: 1;transition: 0.2s;z-index: 20;}.draw-btn:active { filter: brightness(0.93);}.float-num {position: absolute;width: 80px; height: 80px;border-radius: 50%;background: linear-gradient(135deg,#ffb6c1 0%,#fff0f5 100%);color: #d72660;font-size: 1.9em;font-weight: bold;display: flex;align-items: center;justify-content: center;box-shadow: 0 3px 18px #ffb6c1a0;border: 3px solid #f8bbd0;user-select: none;pointer-events: none;transition: box-shadow 0.18s, transform 0.18s;animation: breatheBubble 2.2s infinite alternate;}@keyframes breatheBubble {0% { box-shadow: 0 3px 18px #ffb6c1a0; }100% { box-shadow: 0 8px 50px #ffd1e0a0, 0 0 28px #fff0f5cc inset;}}.float-num .heart {position: absolute;left: 50%; bottom: -12px;transform: translateX(-50%);font-size: 1.2em;color: #ffb6c1;opacity: 0.8;pointer-events: none;}.float-num.selected {background: linear-gradient(130deg,#e75480 30%,#fff0f7 100%);color: #fff;border: 4px solid #d72660;z-index: 99;animation: popBubble 0.4s cubic-bezier(.41,1.67,.37,1.01), breatheSelected 1.1s infinite alternate;}@keyframes popBubble {0% { transform: scale(1);}60% { transform: scale(1.33) rotate(-16deg);}100% { transform: scale(1) rotate(0);}}@keyframes breatheSelected {0% { box-shadow: 0 0 20px #ffa6c9, 0 0 0 #fff; }100% { box-shadow: 0 0 65px #e75480aa, 0 0 38px #fff0f5cc inset;}}.rings {position: absolute;top: -30px; right: 55px;width: 75px; height: 75px;z-index: 20;pointer-events: none;}.rings svg {width: 100%; height: 100%;}.boy-anim-mask {position: fixed;left: 0; top: 0; right: 0; bottom: 0;width: 100vw; height: 100vh;background: rgba(255,208,220,0.27);z-index: 2000;display: flex;align-items: flex-start;justify-content: center;cursor: pointer;animation: boyFadeInBg 0.38s;}@keyframes boyFadeInBg {from {background: rgba(255,208,220,0);}to   {background: rgba(255,208,220,0.27);}}.boy-anim-content {margin-top: -350px;animation: boySlideIn 1.0s cubic-bezier(.22,1.1,.45,1.01) forwards;display: flex;flex-direction: column;align-items: center;filter: drop-shadow(0 10px 32px #f8bbd0dd);}@keyframes boySlideIn {from { margin-top: -350px; opacity: 0; }80% { opacity: 1; }to { margin-top: 80px; opacity: 1; }}.boy-svg-wrap {width: 230px;height: 300px;position: relative;}.boy-num-holder {position: absolute;left: 50%;top: 62px;transform: translateX(-50%);width: 95px; height: 62px;background: #fffbe7;border-radius: 22px 22px 30px 30px;border: 3.5px solid #ffd5a6;display: flex;align-items: center;justify-content: center;font-size: 2.5em;font-weight: bold;color: #e75480;z-index: 2;box-shadow: 0 4px 16px #ffe1c1c1;letter-spacing: 2px;}.boy-win-text {margin-top: 18px;font-size: 2em;color: #d72660;font-weight: bold;text-shadow: 0 2px 10px #fff7e0;animation: textPop 1s;}@keyframes textPop {0%{ transform: scale(0.7); opacity: 0;}80%{ transform: scale(1.08);}100%{ transform: scale(1); opacity: 1;}}@media (max-width: 1300px) {.container { width: 98vw; min-width:320px; }.draw-btn { top: 83vh;}}@media (max-width: 800px) {.container { width: 100vw; height: 95vh; }}</style>
</head>
<body><!-- 顶部跑马灯 --><div class="marquee-bar-wrap" id="marqueeBarWrap"><div class="marquee-bar-content" id="marqueeBarContent"></div></div><div class="container" id="float-area" style="top:calc(50% + 23px);"><div class="title-area"><h1>幸福婚礼抽奖</h1><div class="subtitle">各位宾客,谁会成为幸运儿?</div></div><button class="draw-btn" id="drawBtn">💍 抽奖</button><div class="rings"><svg viewBox="0 0 80 60"><ellipse cx="30" cy="30" rx="18" ry="18" fill="#ffe4e9" stroke="#d72660" stroke-width="3"/><ellipse cx="50" cy="30" rx="18" ry="18" fill="#fff0f5" stroke="#b23a48" stroke-width="3"/><rect x="24" y="10" width="12" height="8" rx="2" fill="#ffe4b5" stroke="#b23a48" stroke-width="2" transform="rotate(-15 30 14)"/></svg></div></div><!-- 动画小男孩中奖展示 --><div id="boyMask" style="display:none;"></div>
<script>
// -------- 跑马灯部分 --------
const marqueeContent = '欢迎各位宾客参加我们的婚礼,祝大家幸福美满!抽奖即将开始,祝您好运~';
// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
// 在此修改要轮播展示的内容function setMarqueeText(txt){const ele = document.getElementById('marqueeBarContent');// 复制内容两遍用于连续无缝循环ele.innerHTML = txt + '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0'+ txt;// 动态调整动画时长(越长越慢)setTimeout(function(){let w = ele.offsetWidth;let speed = Math.max(12, w/80); // 保证长内容也较慢ele.style.animationDuration = speed+'s';},80);
}
setMarqueeText(marqueeContent);// -------- 主抽奖部分 --------
const floatArea = document.getElementById('float-area');
const areaW = ()=>floatArea.clientWidth;
const areaH = ()=>floatArea.clientHeight;
const BALL_SIZE = 80;
const BALL_NUM = 30;
let balls = [];
let ballElements = [];
let animReq = null;// 1. 生成不重叠的初始位置和速度
function genBalls() {balls = [];ballElements = [];for(let i=1; i<=BALL_NUM; i++) {let tries = 0, maxTry=500, ok = false, bx,by;do {bx = 80 + Math.random()*(areaW()-BALL_SIZE-180);by = 90 + Math.random()*(areaH()-BALL_SIZE-200);ok = balls.every(b => Math.hypot(b.x-bx, b.y-by)>BALL_SIZE*1.07);tries++;} while(!ok && tries<maxTry);let speed = 1.3+Math.random()*0.8;let angle = Math.random()*2*Math.PI;balls.push({num: i,x: bx, y: by,vx: speed*Math.cos(angle),vy: speed*Math.sin(angle)});}
}// 2. 渲染气泡
function renderBalls() {for(const ele of ballElements) floatArea.removeChild(ele);ballElements = [];for(let i=0;i<balls.length;i++) {let b = balls[i];let div = document.createElement('div');div.className = 'float-num';div.style.left = b.x+'px';div.style.top  = b.y+'px';div.innerHTML = `<span>${b.num}</span><span class="heart">❤</span>`;floatArea.appendChild(div);ballElements.push(div);}
}
genBalls();
renderBalls();// 3. 漂浮动画循环
function floatLoop() {for(let i=0;i<balls.length;i++) {let b = balls[i];// 边界反弹if(b.x+b.vx<2) { b.vx = Math.abs(b.vx);}if(b.x+b.vx > areaW()-BALL_SIZE-2) { b.vx = -Math.abs(b.vx);}if(b.y+b.vy<40) { b.vy = Math.abs(b.vy);}if(b.y+b.vy > areaH()-BALL_SIZE-2) { b.vy = -Math.abs(b.vy);}// 与其它小球简单互斥距离(弹弹弹)for(let j=0;j<balls.length;j++) if(i!==j){let b2=balls[j],dx=b.x-b2.x,dy=b.y-b2.y;let d = Math.hypot(dx,dy);if(d>0 && d<BALL_SIZE*0.98){let overlap = (BALL_SIZE*0.98-d)/2;b.x += dx/d*overlap;b.y += dy/d*overlap;}}// 随机微调速度让气泡轨迹更活泼if(Math.random()<0.009) {let angle = Math.atan2(b.vy, b.vx)+((Math.random()-0.5)*0.7);let speed = (1.1+Math.random()*0.9);b.vx = speed*Math.cos(angle);b.vy = speed*Math.sin(angle);}b.x += b.vx;b.y += b.vy;let div = ballElements[i];div.style.left = b.x+'px';div.style.top = b.y+'px';}animReq = requestAnimationFrame(floatLoop);
}
floatLoop();// 4. 抽奖核心
let currentSelectedIdx = null;
const boyMask = document.getElementById('boyMask');function drawLottery() {// 动画高亮闪烁let idx = 0, step=0;let rounds = Math.floor(Math.random()*2)+2;let totalSteps = rounds*balls.length + Math.floor(Math.random()*balls.length);document.getElementById('drawBtn').disabled = true;function highlightNext() {ballElements.forEach((div,i)=>div.classList.remove('selected'));idx = step%balls.length;ballElements[idx].classList.add('selected');step++;if(step<=totalSteps){let delay;if(step < totalSteps * 0.2) delay = 27;else if(step > totalSteps * 0.85) delay = 130;else delay = 47;setTimeout(highlightNext, delay);}else{currentSelectedIdx = idx;setTimeout(()=>showBoyAnim(balls[idx].num),320);}}highlightNext();
}// 5. 小男孩动画中奖展示
function showBoyAnim(num){// 1. 内容填充boyMask.innerHTML = `<div class="boy-anim-mask" onclick="closeBoyAnim()"><div class="boy-anim-content" onclick="event.stopPropagation()"><div class="boy-svg-wrap"><svg width="230" height="300" viewBox="0 0 230 300"><rect x="108" y="15" width="16" height="72" rx="9" fill="#ffe4b5" transform="rotate(-7 108 15)" /><ellipse cx="115" cy="20" rx="11" ry="13" fill="#ffd2be" /><ellipse cx="115" cy="75" rx="46" ry="45" fill="#ffe4b5" stroke="#eac086" stroke-width="3"/><ellipse cx="70" cy="88" rx="8" ry="13" fill="#ffd2be" /><ellipse cx="160" cy="88" rx="8" ry="13" fill="#ffd2be" /><path d="M73 62 Q115 17 157 62 Q142 50 115 53 Q88 50 73 62Z" fill="#3f2b1c"/><ellipse cx="115" cy="52" rx="38" ry="13" fill="#3f2b1c"/><ellipse cx="99" cy="60" rx="9" ry="7.5" fill="#3f2b1c"/><ellipse cx="131" cy="60" rx="10" ry="8" fill="#3f2b1c"/><ellipse cx="100" cy="88" rx="6" ry="9" fill="#fff"/><ellipse cx="130" cy="88" rx="6" ry="9" fill="#fff"/><ellipse cx="100" cy="90" rx="2.3" ry="3" fill="#3f2b1c"/><ellipse cx="130" cy="90" rx="2.3" ry="3" fill="#3f2b1c"/><path d="M105 110 Q115 122 125 110" stroke="#b26d59" stroke-width="2.2" fill="none"/><ellipse cx="115" cy="101" rx="3.5" ry="1.6" fill="#b26d59" opacity="0.3"/><rect x="85" y="120" width="60" height="72" rx="28" fill="#7fd5ff" stroke="#5ca3c7" stroke-width="3"/><rect x="37" y="135" width="22" height="64" rx="11" fill="#ffe4b5" transform="rotate(16 50 135)" /><ellipse cx="53" cy="202" rx="11" ry="10" fill="#ffd2be"/><rect x="153" y="140" width="22" height="64" rx="11" fill="#ffe4b5" transform="rotate(-14 164 140)" /><ellipse cx="169" cy="202" rx="11" ry="10" fill="#ffd2be"/><rect x="93" y="193" width="17" height="36" rx="8" fill="#3c6384"/><rect x="120" y="193" width="17" height="36" rx="8" fill="#3c6384"/><ellipse cx="102" cy="232" rx="12" ry="7" fill="#4e2727"/><ellipse cx="128" cy="232" rx="12" ry="7" fill="#4e2727"/></svg><div class="boy-num-holder">${num}</div></div><div class="boy-win-text">🎉 恭喜 ${num} 号中奖!</div></div></div>`;boyMask.style.display = 'block';setTimeout(()=>{ document.getElementById('drawBtn').disabled = false; },1500);
}
function closeBoyAnim(){boyMask.style.display = "none";ballElements.forEach(div=>div.classList.remove('selected'));
}
window.closeBoyAnim = closeBoyAnim;document.getElementById('drawBtn').addEventListener('click', function(){drawLottery();
});window.addEventListener('resize', ()=>{cancelAnimationFrame(animReq);genBalls();renderBalls();floatLoop();
});
</script>
</body>
</html>

程序截图
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/pingmian/93154.shtml
繁体地址,请注明出处:http://hk.pswp.cn/pingmian/93154.shtml
英文地址,请注明出处:http://en.pswp.cn/pingmian/93154.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Python办公】Excel转json(极速版)-可自定义累加字段(如有重复KEY)

目录 专栏导读 🎯 亮点特性 ⚙️ 安装与运行 🖥️ 界面与区域说明 🚀 使用示例 💡 使用建议 ❓ 常见问题(FAQ) 🧱 技术要点 完整代码 🏁 结语 专栏导读 🌸 欢迎来到Python办公自动化专栏—Python处理办公问题,解放您的双手 🏳️‍🌈 博客主页:请点击——…

JavaScript 防抖(Debounce)与节流(Throttle)

在 JavaScript 前端开发中&#xff0c;处理高频率事件&#xff08;如窗口调整、输入框输入、页面滚动&#xff09;时&#xff0c;如果不加以控制&#xff0c;会导致性能问题&#xff0c;如页面卡顿或资源浪费。防抖&#xff08;Debounce&#xff09;和节流&#xff08;Throttle…

探索无人机图传技术:创新视野与无限可能

近年来&#xff0c;无人机技术的飞速发展不仅改变了航空行业的格局&#xff0c;还深刻影响了多个领域的日常运作。无人机图传技术作为无人机的核心技术之一&#xff0c;凭借其精准的图像传输能力和高效的远程操作特性&#xff0c;正在成为各行各业的得力助手。从空中拍摄到实时…

Comfyui进入python虚拟环境

如果你的 Python 可执行文件&#xff08;python.exe&#xff09;位于 C:\comfyui\.venv\Scripts&#xff0c;那么 .venv 本身已经是一个虚拟环境&#xff0c;你只需要 激活它&#xff0c;而无需再创建一个新的虚拟环境。如何激活这个已有的虚拟环境&#xff1f; 1. 打开终端&am…

秋招春招实习百度笔试百度管培生笔试题库百度非技术岗笔试|笔试解析和攻略|题库分享

笔试介绍 百度非技术岗笔试采用的是规定时间统一笔试形式&#xff0c;管培生会有两场考试分别是7月底和8月中旬&#xff0c;其他非技术类岗位一般在8月中旬开始。 行测题必考&#xff0c;有些岗位考简答题&#xff0c;比如管培生以及产品经理等岗位。 笔试内容 笔试内容一…

低资源语言翻译:数据增强与跨语言迁移学习策略

文章目录一、低资源语言翻译的挑战1.1 数据稀缺性1.2 语言特性复杂1.3 评估困难二、数据增强策略&#xff08;Data Augmentation&#xff09;2.1 基于单语数据的增强2.2 基于平行数据的增强2.3 多模态数据增强三、跨语言迁移学习策略&#xff08;Cross-Lingual Transfer Learni…

【每天一个知识点】时间序列聚类

一、什么是时间序列聚类&#xff1f;如果把数据比作一本书&#xff0c;那么时间序列&#xff08;Time Series&#xff09;就是一本按时间顺序记录事件的日记。它可能是股票每天的价格波动、某台机器的温度曲线、一个城市的空气质量变化&#xff0c;甚至是人的心电信号。时间序列…

对抗损失(GAN)【生成器+判断器】

这个是啥呢&#xff0c;搞图片生成用的。我搜了下&#xff0c;把整体流程记录下&#xff0c;过程中会用到GAN准备数据集&#xff08;真实图像素材&#xff09; 目标生成人脸的&#xff0c;你像游戏注册时选一个脸。捏脸。那么准备真实人脸图片老规矩&#xff0c;缩放裁剪…

5分钟入门C++

这是5分钟入门 C 的精简 Demo&#xff0c;尽量涵盖核心概念&#xff1a;变量、函数、类、控制流、STL 容器&#xff0c;让你快速理解 C 的基本用法。#include <iostream> // 输入输出 #include <vector> // 动态数组 #include <algorithm> // 常用算法…

java注释功能

为了优化代码的使用&#xff0c;分享记录相关注释功能。 单行注释 // 这是单行注释文字多行注释 /* 这是多行注释文字 这是多行注释文字 注意&#xff1a;多行注释不能嵌套使用。 */文档注释 /**- 这是文档注释文字- */注释的作用 描述类或方法的功能&#xff0c;方便别人和自…

(论文速读)DiffusionDet - 扩散模型在目标检测中的开创性应用

论文题目&#xff1a;DiffusionDet: Diffusion Model for Object Detection&#xff08;DiffusionDet:物体检测的扩散模型&#xff09;会议&#xff1a;ICCV2023摘要&#xff1a;我们提出了DiffusionDet&#xff0c;这是一个新的框架&#xff0c;它将物体检测描述为从噪声盒到目…

LangChain简介

LangChain 是一个用于构建基于大语言模型&#xff08;LLM&#xff09;的应用程序的开源框架&#xff0c;它提供了一套工具、组件和接口&#xff0c; 可以将 LLM 模型、向量数据库、交互层 Prompt、外部知识、外部工具整合到一起&#xff0c;进而可以自由构建 LLM 应用。 LangCh…

为什么哈希表(字典)的查询速度有时会突然变慢

哈希表&#xff08;在许多语言中被称为“字典”或“关联数组”&#xff09;的查询速度&#xff0c;在理想情况下&#xff0c;应是接近“瞬时”的常数时间&#xff0c;然而&#xff0c;在特定场景下&#xff0c;其性能之所以会突然、无征兆地变慢&#xff0c;其根源&#xff0c;…

whisper 语种检测学习笔记

目录 transformers推理&#xff1a; transformers 源代码 网上的语种检测调用例子&#xff1a; 语种检测 api transformers推理&#xff1a; https://github.com/openai/whisper/blob/c0d2f624c09dc18e709e37c2ad90c039a4eb72a2/whisper/decoding.py waveform, sample_rat…

第1节 从函数到神经网络:AI思路的逆袭之路

&#x1f914; 开篇灵魂拷问 是不是觉得AI知识体系庞大到吓人&#xff1f;看了一堆快餐视频还是云里雾里&#xff1f;别慌&#xff01;这个系列就是要帮你打通任督二脉&#xff0c;用"既快又慢、既深入又肤浅、既有趣又严肃"的方式讲透AI基础知识&#xff01; &…

【科研绘图系列】R语言绘制多种饼图

文章目录 介绍 加载R包 数据下载 导入数据 数据预处理 画图1 画图2 画图3 画图4 画图5 画图6 系统信息 参考 介绍 【科研绘图系列】R语言绘制多种饼图 加载R包 rm(list = ls()) library(ggstatsplot) library(ggplot2) library(plotrix) library(ggpubr

vue3权限树封装成组件

vue3权限树组件 功能&#xff1a; 1、勾选节点、自动把父节点勾选。 2、取消勾选、子节点全部取消勾选。检查父节点&#xff0c;如果只有这个子节点、遍历把父节点取消勾选 3、filter过滤不仅展示父节点、相关子节点同时展示 4、 高亮显示所有过滤数据 效果图父组件引用 <te…

铨林接纸机学习记录1

光电开关学习做保养也是检查这些东西&#xff0c;包括气路有没漏气&#xff0c;固定件松动、轨道清洁之内刀座暂停光电I23刀座行程磁性开关&#xff0c;这个是安全警戒光电&#xff0c;驱动侧发射信号&#xff0c;操作侧接收刀座暂停光电正常运行是空白的&#xff0c;当出现遮挡…

47.分布式事务理论

所有的事务都必须满足ACID的原则: 原子性:事务中的所有操作,要么全部成功,要么全部失败。 一致性:要保证数据库内部完整性约束、声明性约束。 持久性:对数据库做的一切修改将永久保存,不管是否出现故障。 隔离性:对同一资源操作的事务不能同时发生。 分布式事务的…

【软考】进度管理知识库工具-挺方便

进度管理知识库 全面解析项目管理中的进度管理核心概念、工具、技术和最佳实践&#xff0c;帮助您高效管理项目时间线 六步流程法 规划进度管理 - 制定进度管理计划 定义活动 - 识别和记录项目活动 排列活动顺序 - 确定活动间的逻辑关系 估算活动持续时间 - 估算完成单项活动所…