zoukankan      html  css  js  c++  java
  • jquery----抽奖系统

    1、效果

    2、html代码

    <!DOCTYPE html>
    <html>
    
    <head>
        <meta charset="utf-8">
        <title>九宫格</title>
        <link rel="stylesheet" type="text/css" href="css/nineBoxGame.less">
    </head>
    
    <body>
        <div class="head">
            <h2>抽奖环节</h2>
        </div>
        <div class="nine-box-game">
            <div class="title">
                <div class="left">
                    <span>?</span>
                </div>
                <div class="right">??????</div>
            </div>
            <div class="content">
                <div class="line1 line">
                    <div class="list list1 choose" data-type='1'>
                        <div class="img">
                            <img src="imgs/20.png">
                        </div>
                        <div class="txt">
                            0奥利蒂克户外包
                        </div>
                    </div>
                    <div class="list list2" data-type='2'>
                        <div class="img">
                            <img src="imgs/21.png">
                        </div>
                        <div class="txt">
                            0奥利蒂克户外包
                        </div>
                    </div>
                    <div class="list list3" data-type='3'>
                        <div class="img">
                            <img src="imgs/22.png">
                        </div>
                        <div class="txt">
                            0奥利蒂克户外包
                        </div>
                    </div>
                </div>
                <div class="line2 line">
                    <div class="list list8" data-type='8'>
                        <div class="img">
                            <img src="imgs/23.png">
                        </div>
                        <div class="txt">
                            0奥利蒂克户外包
                        </div>
                    </div>
                    <div class="list one-more">
                        <p><span></span></p>
                        <p>
                            再抽一次
                        </p>
                        <p><span></span></p>
                    </div>
                    <div class="list list4 thanks" data-type='4'>
                        谢谢参与
                    </div>
                </div>
                <div class="line3 line">
                    <div class="list list7" data-type='7'>
                        <div class="img">
                            <img src="imgs/24.png">
                        </div>
                        <div class="txt">
                            0奥利蒂克户外包
                        </div>
                    </div>
                    <div class="list list6" data-type='6'>
                        <div class="img">
                            <img src="imgs/25.png">
                        </div>
                        <div class="txt">
                            0奥利蒂克户外包
                        </div>
                    </div>
                    <div class="list list5" data-type='5'>
                        <div class="img">
                            <img src="imgs/26.png">
                        </div>
                        <div class="txt">
                            0奥利蒂克户外包
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script type="text/javascript" src='js/jquery.min.js'></script>
        <script type="text/javascript" src='js/nineBoxGame.js'></script>
    </body>
    
    </html>
    

      3、js代码

    (function(widow, $) {
        $(function() {
            nineBoxGame();
        })
        var is_start = true;
        var speed = 1;
        var is_run = false;
    
        function nineBoxGame() {
            var parent = $(".nine-box-game");
            var oneMore = parent.find(".one-more");
            oneMore.on("click", function() {
                $.ajax({
                    method: "get",
                    url: "http://student.bluej.cn/index/index/lucky_draw2?max_num=100&callback=lucky_num",
                    async: true,
                    dataType: "jsonp",
                    data: "",
                    callback: "lucky_num",
                    success: function(res) {
                        var num = res[0].num;
                        console.log(num);
                        if (mainEvent(num)) {
                            is_start = false;
                        }
                    },
                    error: function(res) {
                        console.log(res);
                    }
                })
            })
        }
    
        function mainEvent(getWhat) {
            var choose = 1;
            var interval = 100;
            var clock;
            var time = 0;
            var getWhat = getWhat % 8;
            var parent = $(".nine-box-game");
            var goldImg = parent.find(".title .left span");
            var goldTxt = parent.find(".title .right");
            var prizeList = parent.find(".content .line .list");
            var oneMore = parent.find(".one-more");
            if (is_start) {
                var sp = 1;
                clock = setInterval(function() {
                    if(time>46){
                        console.log(time+":"+is_run);
                        if(speed!=sp){
                           sp++;
                            is_run = false;
                        }
                        else{
                            sp = 1;
                            speed += 3;
                            is_run = true;
                        }
                    }
                    else{
                        if(sp == speed){
                             is_run = true;
                        }
                    }
                    if (is_run) {
                        goldImg.attr("style", "");
                        goldImg.text("?");
                        goldTxt.text("???????");
                        time++;
                        console.log(time);
                        choose < 8 ? choose++ : choose = 1;
                        var target = parent.find(".list" + choose);
                        parent.find(".list").removeClass("choose");
                        target.addClass("choose");
                        if (getWhat == choose && time > 50) {
                            clearInterval(clock);
                            is_start = true;
                            time = 0;
                            if (getWhat == 4) {
                                goldImg.text("?");
                                goldTxt.text("谢谢参与!");
                            } else {
                                var url = parent.find(".list" + getWhat + " .img img").attr("src");
                                var txt = parent.find(".list" + getWhat + " .txt").text().trim();
                                goldImg.attr("style", "background-image:url('" + url + "');");
                                goldImg.text("");
                                goldTxt.text(txt);
                            }
                        }
                    }
                }, interval)
            }
            return 1;
        }
    })(window, jQuery)
    

      

      

      4、css代码

    * {
        margin: 0;
        padding: 0;
    }
    
    body {
         100%;
        height: 100%;
        background-color: #17C4F1;
    }
    
    .head {
         100%;
        height: 60px;
        line-height: 60px;
        text-align: center;
        background-color: #0093B9;
        color: white;
        font-size: 24px;
    }
    
    .nine-box-game {
         455px;
        height: 800px;
        margin: 0 auto;
        .title {
             400px;
            height: 258px;
            .left {
                 220px;
                height: 258px;
                float: left;
                background-image: url("/imgs/gold.png");
                background-size: 160px 258px;
                background-repeat: no-repeat;
                background-position: 30px 0px;
                position: relative;
                top: 0;
                left: 0;
                span {
                    display: inline-block;
                     80px;
                    height: 80px;
                    color: #F9CB4E;
                    font-size: 80px;
                    line-height: 70px;
                    text-align: center;
                    margin: 144px 0 0 70px;
                    background-size: 80px 80px;
                }
            }
            .right {
                float: left;
                line-height: 258px;
                font-size: 16px;
                color: white;
            }
        }
        .content {
             404px;
            height: 42px;
            margin: 20px auto 0 auto;
            .line {
                 404px;
                float: left;
                margin: 0 0 10px 0;
                .list {
                     128px;
                    height: 128px;
                    text-align: center;
                    box-sizing: border-box;
                    background-color: white;
                    border: 10px solid #DBDBDD;
                    float: left;
                    .img {
                         90px;
                        height: 90px;
                        overflow: hidden;
                        margin: 0 auto;
                        img {
                             90px;
                            height: 100%;
                        }
                    }
                    .txt {}
                    &:nth-child(3n+1),
                    &:nth-child(3n+2) {
                        margin: 0px 10px 0 0;
                    }
                }
                .choose {
                    border: 10px solid red;
                }
                .one-more {
                    position: relative;
                    top: 0;
                    left: 0;
                    cursor: pointer;
                    p:nth-child(1) {
                        position: absolute;
                        top: 0;
                        left: 0;
                        height: 8px;
                         108px;
                        background-color: #FF6146;
                        margin: 0;
                        padding: 0;
                        span {
                            display: inline-block;
                             34px;
                            height: 8px;
                            background-color: white;
                            float: left;
                            margin: 0 0 0 36px;
                        }
                    }
                    p:nth-child(2) {
                        position: absolute;
                        top: 8px;
                        left: 0;
                         68px;
                        padding: 20px;
                        height: 52px;
                        font-size: 24px;
                        color: #FD471F;
                        background-color: #FFEF3B;
                    }
                    p:nth-child(3) {
                        position: absolute;
                        bottom: 0;
                        left: 0;
                        height: 8px;
                         108px;
                        background-color: #FF6146;
                        margin: 0;
                        padding: 0;
                        span {
                            display: inline-block;
                             34px;
                            height: 8px;
                            background-color: white;
                            float: left;
                            margin: 0 0 0 36px;
                        }
                    }
                }
            }
            .thanks {
                padding: 20px;
                font-size: 24px;
                color: #BDBCBA;
            }
        }
    }
    

      5、总结:

    a、中奖选项事先随机生成,并且定义好每个奖项出现的概率

  • 相关阅读:
    八大排序(一)-------冒泡排序
    vs code 常用插件记录
    vc code 透明背景图片配置
    .Net FrameWork获取配置文件信息
    c#中关于Convert.ToDouble的一个注意事项
    JsonArray
    webpack打包(二)
    了解webpack(一)
    vue组件的封装
    DIV+CSS必须知道的事
  • 原文地址:https://www.cnblogs.com/SunlikeLWL/p/7366497.html
Copyright © 2011-2022 走看看