当前位置: 首页 > news >正文

浏览器打开抽奖系统html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>在线抽奖 随机选取 自动挑选</title>
<script src="https://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<style>
body {background-color: aliceblue;
}
.wrapDiv {width: 80%;max-width: 1200px;margin: 0 auto;text-align: center;position: absolute;top: 80px;left: 0;right: 0;
}
.leftBox {float: left;width: 800px;height: 240px;margin: 0 auto;margin-top: 0px;clear: both;
}
#span {float: right;top: 30px;right: 185px;
}
#btn {float: left;width: 200px;height: 100px;text-align: center;line-height: 100px;margin-left: 500px;margin-top: 200px;background: linear-gradient(to right, #ff0000, #ff9900, #ffff00, #33cc33, #3399ff); /* 设置背景渐变 */color: white;font-size: 18px;font-weight: bold;border: none;cursor: pointer;
}.nameBox {width: 200px;height: 50px;float: left;margin-left: 10px;margin-top: 10px;text-align: center;line-height: 50px;
}.nameBox:nth-child(1) {background-color: #f44336; /* 红色 */
}.nameBox:nth-child(2) {background-color: #9c27b0; /* 紫色 */
}.nameBox:nth-child(3) {background-color: #2196f3; /* 蓝色 */
}.nameBox:nth-child(4) {background-color: #4caf50; /* 绿色 */
}.nameBox:nth-child(5) {background-color: #ff9800; /* 橙色 */
}.nameBox:nth-child(6) {background-color: #ffeb3b; /* 黄色 */
}.nameBox:nth-child(7) {background-color: #00bcd4; /* 青色 */
}.nameBox:nth-child(8) {background-color: #e91e63; /* 桃红色 */
}.nameBox:nth-child(9) {background-color: #8bc34a; /* 浅绿色 */
}.nameBox:nth-child(10) {background-color: #607d8b; /* 钢蓝色 */
}.nameBox:nth-child(11) {background-color: #673ab7; /* 深紫色 */
}.nameBox:nth-child(12) {background-color: #ff5722; /* 橙红色 */
}.nameBox:nth-child(13) {background-color: #3f51b5; /* 中蓝色 */
}.nameBox:nth-child(14) {background-color: #795548; /* 暗褐色 */
}.nameBox:nth-child(15) {background-color: #009688; /* 深绿色 */
}.nameBox:nth-child(16) {background-color: #ff4081; /* 粉红色 */
}.nameBox:nth-child(17) {background-color: #9e9e9e; /* 灰色 */
}.nameBox:nth-child(18) {background-color: #ffc107; /* 金黄色 */
}.nameBox:nth-child(19) {background-color: #cddc39; /* 青绿色 */
}.nameBox:nth-child(20) {background-color: #03a9f4; /* 亮蓝色 */
}.nameBox:nth-child(21) {background-color: #ff1744; /* 鲜红色 */
}/* 可以继续定义更多的 .nameBox:nth-child(n) 规则来设置不同的颜色 */.selectedName {float: right;width: 300px;background: #666;margin-top: 10px;margin-left: 30px;background: #ffffff;overflow-y: scroll; /* 添加垂直滚动条 */
}h1 {text-align: center;
}
</style>
</head>
<body>
<h1>随机抽奖系统</h1>
<span id="span"></span><div class="wrapDiv"><div id="leftBox" class="leftBox"></div><div id="selectedName" class="selectedName"><h1>礼物</h1><!-- 中奖者名单内容将动态添加 --></div><input type="button" id="btn" value="点这里开启幸运之旅">
</div><script>
// 模拟后台数据
var arr = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10","11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21",
];var orgArrCount = arr.length;
var currentSelectNum = 0;initForm();// 初始化表单
function initForm() {// 动态设置选择人的高度var selectedNameHeight = orgArrCount / 3 * 40 + 300;$("#selectedName").css("height", selectedNameHeight + "px");// 动态创建图层dynamicCreateBox();
}// 动态创建层
function dynamicCreateBox() {for (var i = 0; i < arr.length; i++) {var div = document.createElement("div");div.innerText = arr[i];div.className = "nameBox";$("#leftBox").append(div);};
}// 清空小方格颜色
function clearBoxColor() {$("#leftBox").children("div").each(function() {$(this).css("background-color", "");});
}// 设置选中小方格颜色
function setBoxColor() {$("#leftBox").children("div").each(function() {var thisText = ($(this).text());var selectedName = arr[currentSelectNum];if (thisText == selectedName) {$(this).css("background-color", "red");}});
}function appendSelectedName() {var div = document.createElement("div");div.innerText = arr[currentSelectNum];div.className = "nameBox";$("#selectedName").append(div);
}$('#btn').click(function() {var curentCount = arr.length;if (curentCount < 1) {alert("已经抽完这个奖池了");// 清空所有层的颜色clearBoxColor();return;}// 监视按钮的状态if (this.value === "点这里开启幸运之旅") {// 定时针timeId = setInterval(function() {// 清空所有层的颜色clearBoxColor();//随机生成一个数var num = Math.floor(Math.random() * curentCount);currentSelectNum = num;// 设置选中小方格颜色setBoxColor();}, 10);this.value = "停止";} else {// 清除计时器clearInterval(timeId);// 添加选中人appendSelectedName();// 移除arr.splice(currentSelectNum, 1);this.value = "点这里开启幸运之旅";}
});// 获取时间的函数
getTime();
setInterval(getTime, 10)function getTime() {var day = new Date();var year = day.getFullYear(); //年var month = day.getMonth() + 1; //月var dat = day.getDate(); //日var hour = day.getHours(); //小时var minitue = day.getMinutes(); //分钟var second = day.getSeconds(); //秒month = month < 10 ? "0" + month : month;dat = dat < 10 ? "0" + dat : dat;hour = hour < 10 ? "0" + hour : hour;minitue = minitue < 10 ? "0" + minitue : minitue;second = second < 10 ? "0" + second : second;$("#span").text(year + "-" + month + "-" + dat + " " + hour + ":" + minitue + ":" + second);
}
</script></body>
</html>

 

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 怎么使用github上传XXX内所有文件
  • springboot给属性赋值的两种方式(yaml与properties)
  • 大学生算法高等数学学习平台设计方案 (第一版)
  • 昇思25天学习打卡营第22天|CV-Vision Transformer图像分类
  • MySQL 和 SQL Server 中的连表更新 UPDATE JOIN 写法比较
  • Webshell管理工具:AntSword(中国蚁剑)
  • CentOS怎么关闭自动锁屏?
  • 【学一点儿前端】本地或jenkins打包报错:getaddrinfo ENOTFOUND registry.nlark.com.
  • Docker学习与实战
  • SpringSecurity如何正确的设置白名单
  • MySQL中多表查询之外连接
  • 网络基础之(11)优秀学习资料
  • Linux - 进程的概念、状态、僵尸进程、孤儿进程及进程优先级
  • 蓝桥杯 2024 年第十五届省赛真题 —— 最大异或结点
  • Linux系统编程——生产者消费者模型
  • eclipse的离线汉化
  • HashMap ConcurrentHashMap
  • JavaScript/HTML5图表开发工具JavaScript Charts v3.19.6发布【附下载】
  • JavaScript创建对象的四种方式
  • Java多态
  • React组件设计模式(一)
  • Sublime Text 2/3 绑定Eclipse快捷键
  • webpack项目中使用grunt监听文件变动自动打包编译
  • 阿里云Kubernetes容器服务上体验Knative
  • 不发不行!Netty集成文字图片聊天室外加TCP/IP软硬件通信
  • 嵌入式文件系统
  • 使用common-codec进行md5加密
  • 事件委托的小应用
  • LIGO、Virgo第三轮探测告捷,同时探测到一对黑洞合并产生的引力波事件 ...
  • 蚂蚁金服CTO程立:真正的技术革命才刚刚开始
  • ​ 全球云科技基础设施:亚马逊云科技的海外服务器网络如何演进
  • ​iOS实时查看App运行日志
  • ​二进制运算符:(与运算)、|(或运算)、~(取反运算)、^(异或运算)、位移运算符​
  • !!java web学习笔记(一到五)
  • # Apache SeaTunnel 究竟是什么?
  • #if和#ifdef区别
  • #include<初见C语言之指针(5)>
  • #传输# #传输数据判断#
  • $(this) 和 this 关键字在 jQuery 中有何不同?
  • (Arcgis)Python编程批量将HDF5文件转换为TIFF格式并应用地理转换和投影信息
  • (C语言版)链表(三)——实现双向链表创建、删除、插入、释放内存等简单操作...
  • (Matlab)使用竞争神经网络实现数据聚类
  • (附源码)ssm捐赠救助系统 毕业设计 060945
  • (六)库存超卖案例实战——使用mysql分布式锁解决“超卖”问题
  • (七)Flink Watermark
  • (一一四)第九章编程练习
  • (转)es进行聚合操作时提示Fielddata is disabled on text fields by default
  • (转)http-server应用
  • .NET Reactor简单使用教程
  • .NET导入Excel数据
  • @Import注解详解
  • [ MSF使用实例 ] 利用永恒之蓝(MS17-010)漏洞导致windows靶机蓝屏并获取靶机权限
  • [1525]字符统计2 (哈希)SDUT
  • [2021ICPC济南 L] Strange Series (Bell 数 多项式exp)
  • [AI Google] 使用 Gemini 取得更多成就:试用 1.5 Pro 和更多智能功能