浏览器打开抽奖系统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>

 

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
想要利用HTML实现抽奖并显示图片,可以通过以下步骤完成。 首先,需要准备好抽奖相关的图片。可以将这些图片保存在服务器上,也可以将它们直接放在网页的某个文件夹下。 然后,在HTML文件中创建一个抽奖按钮的元素,比如使用按钮(<button>)标签。可以给按钮一个唯一的ID,用于后续的JavaScript操作。 接下来,在HTML文件中创建一个图片显示的元素,比如使用图像(<img>)标签。同样,给图片元素设定一个唯一的ID。 在HTML文件中添加一段JavaScript代码,用于实现抽奖和显示图片的功能。以点击抽奖按钮为触发事件,通过JavaScript随机选择一张图片,然后将它显示在图片元素中。可以使用Math.random()函数来生成一个随机数,再在一组图片中选中一张。 在JavaScript代码中,可以通过调用图片元素的src属性来设置图片的路径。可以使用绝对路径(如果图片保存在服务器上)或相对路径(如果图片保存在当前文件夹下)来指向选中的图片。 最后,在浏览器打开HTML文件,点击抽奖按钮即可实现抽奖并显示图片的效果。 需要注意的是,这个方案只是简单地介绍了使用HTML和JavaScript来实现抽奖显示图片的基本思路。实际操作中可能还需要考虑一些细节,比如如何确保每次抽奖的结果都是随机的,以及如何处理图片无法加载等异常情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值