html5抽奖-html5实现九宫格中奖可固定抽一定奖品

2023-08-23 0 5,641 百度已收录

原生js写的九方抽奖程序(放假在家闲着也闲着)

我写的中奖彩票是用来恶搞我的女同事的,因为每次中奖的结果都是一样的。 。

哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈

我会附上正常的中奖码和只能抽到某一个的固定码;

HTML代码如下⤵️




    
    
    <a href="https://www.wkzy.net/game/tag/%e6%8a%bd%e5%a5%96" title="查看所有文章关于 抽奖"target="_blank">抽奖</a>
    
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        html,
        body,
        .modal-cover {
            width: 100%;
            height: 100%;
        }
        body {
            background: url('./img/background.jpg') no-repeat center;
            background-size: 100% 100%;
            overflow: hidden;
        }
        .container {
            width: 90%;
            height: 300px;
            /* width: 831px; */
            height: 336px;
            /* border: 1px solid; */
            display: flex;
            flex-wrap: wrap;
            margin: 100px auto;
            border-radius: 6px;
            background: #fff;
            padding: 5px 0 5px 10px;
        }
        .item {
            width: 30%;
            height: 30%;
            /* outline: 1px solid black; */
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 18;
            border-radius: 2px;
            /* border: 1px solid; */
            margin: 4px;
            box-shadow: 1px 1px 14px #ccc;
            position: relative;
        }
        .cover {
            position: absolute;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.3);
            top: 0;
            left: 0;
            border-radius: 2px;
        }
        .item-box {
            width: 100%;
            height: 100%;
            background-size: 100% 100%;
            background-repeat: no-repeat;
        }
        .btn-box {
            background-color: #faa5b6;
            cursor: pointer;
            color: #fff;
            font-size: 14px;
            text-align: center;
            line-height: 100px;
        }
        .modal {
            width: 80%;
            height: 150px;
            position: fixed;
            top: 50%;
            left: 50%;
            background: rgba(255, 255, 255, 255);
            border-radius: 4px;
            transform: translate(-50%, -50%);
            text-align: center;
            padding: 20px 10px 10px;
            z-index: 2;
        }
        .modal .confirm-btn {
            background: pink;
            width: 170px;
            height: 40px;
            color: #fff;
            text-align: center;
            line-height: 40px;
            margin: 0 auto;
            margin-top: 20px;
            cursor: pointer;
            border-radius: 4px;
        }
        .modal-cover {
            position: fixed;
            top: 0;
            left: 0;
            background: rgba(0, 0, 0, 0.3);
            z-index: 1;
            display: none;
        }
    


    
开始抽奖

js代码

// 封装工具函数
const util = {
    getELe: (str) => {
        return document.querySelector(str)
    },
    getELes: (str) => {
        return document.querySelectorAll(str)
    }
}
let items = util.getELes(".item-box"),
    covers = util.getELes('.cover'),
    imgArr = ['CHANEL', 'Dior', 'givenchy', 'dabao', 'empty', 'lamer', 'lancome', 'yashilandai', 'YSL', ]
for (let i = 0; i  {
    // 先给所有的奖项盒子加蒙层
    for (let j = 0; j  {
    //         modalInner.innerText = '亲!恭喜你中奖大宝SOD蜜一瓶!^_^ ';
    //         modal.style.display = 'block'
    //         mask.style.display = 'block'
    //     }, 500);
    // }
    // 当等于上面的随机数时
    if (count === rand) {
        clearInterval(stopTimer);
    }
    // 点击再试一次
    tryBtn.addEventListener('click', () => {
        modal.style.display = 'none'
        mask.style.display = 'none'
    })
}
// 给开始按钮绑定点击事件 点击后执行 rotate 
const start = () => {
    console.log(count)
    clearInterval(stopTimer);
    stopTimer = setInterval(rotate, 300);
}
covers[4].addEventListener("click", start);

如果想设置固定奖品html5抽奖,需要自己计算count的值//if(count===40),自己选择几张图片。

复制代码可以直接运行。

最后的效果有点难看。 让我们玩我们想玩的吧。

html5实现九宫格中奖可用于抽奖的这篇文章到此结束。 更多关于html5九宫格获奖内容html5抽奖,请搜索开发者网往期文章或继续浏览下方相关文章。 希望大家继续对脚本之家多多支持!

收藏 (0) 打赏

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

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

悟空资源网 html5 html5抽奖-html5实现九宫格中奖可固定抽一定奖品 https://www.wkzy.net/game/147518.html

常见问题

相关文章

官方客服团队

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