JavaScript概率游戏抽奖根据cookie判断是否填写资料,从而显示相关的提示;判断元素下标是否在随机生成的数组中,有即让其抽奖

来源:互联网 发布:ai高版本软件 编辑:程序博客网 时间:2024/06/01 09:22

/根据cookie判断是否填写资料,从而显示相关的提示;/
if(.cookie('EventsUserName') != null &&.cookie(‘EventsAccount’) != null && $.cookie(‘EventsTel’) != null) {
infoCont.hide();
joinTip.show();

    $ (".tip_joinButt").hide();    joinButt.addClass('success');    $('.receiveButt').addClass('receive')}if($.cookie('EventsUserName') == null && $.cookie('EventsAccount') == null && $.cookie('EventsTel') == null) {    infoCont.show();    joinTip.hide();    joinButt.removeClass('success');    $('.receiveButt').removeClass('receive')} $ (".tip_joinButt").hover (function () {    $ (this).addClass ("egg01_tip");}, function () {$ (this).removeClass ('egg01_tip'); });//tip:世间万事,皆有规则,请填左侧资料,再来游戏一番~//点击报名参加joinButt.on('click', function() {    if(joinButt.hasClass('success')) {        infoCont.hide();        joinTip.show();    }})//弹出提示框function alertShow(obj) {    alterTips_bg.show();    obj.show();    setTimeout(function() {        alterTips_bg.hide();        obj.hide();    }, 1800); //过1秒未填写资料提示框消失}//点击报名参加tree_btn.one('click', function() {    if(joinButt.hasClass('success')) {        //infoCont.hide();        $ (".egg01_tip").hide();        $ (".tip_joinButt").hide();        joinTip.show();        $('#gameCont').css('cursor','url(images/baozhen_13.ico),auto');        $(this).addClass('lingqu');        alertShow(receivetreeTip);    }})$ (".sapling-tip").on('mouseover mouseout',function (e) {    var _this=$(this);    if(tree_btn.hasClass('lingqu') && !_this.hasClass('receive')){        if(e.type=="mouseover"){            _this.find('.sapling_t').show();                            }        else if(e.type == "mouseout"){            //alert(12)            $('.sapling_t').hide();        }    }   });//tip:把绿色还给春天,让红色留给投资!2017一路飘红~~var prizehtml = "";function getEle(arr, num) {    var tempArray = []; //定义一个数组来保存传入的参数数组,可避免直接操作传入的数组    for(var i in arr) {        tempArray.push(arr[i]);    }    var returnArray = []; //定义一个数组来保存随机抽取的元素    for(var j = 0; j < num; j++) {        if(tempArray.length > 0) {            var arrIndex = Math.floor(Math.random() * tempArray.length); //定义随机抽取的元素下标            returnArray[j] = tempArray[arrIndex]; //把抽取的元素赋值给返回的数组            tempArray.splice(arrIndex, 1) //把抽取出来的元素在原数组中删除,避免抽取到重复项        } else {            break; //数组中数据抽取完后,退出循环        }    }    return returnArray;}var list = [0, 1, 2, 3, 4, 5];var randList = getEle(list, 2);var isActive = true;var userId = $('#userId');var clickNum = "";eggButt.on('click', function() {    //未填写资料点击秒杀按钮进行相关提示    //开始点抽奖    //未填写资料点击秒杀按钮进行相关提示            if (!joinButt.hasClass('success')) {        $ (".egg01").hover (function () {                                $ (this).addClass ("egg01_tip");}, function () {                                    $ (this).removeClass ('egg01_tip'); });//tip:世间万事,皆有规则,请填左侧资料,再来游戏一番~      $('html,body').animate({ scrollTop: $('#infoMain').offset().top }, 300);//垂直滚动条值        alertShow(notjoinTip);    }    else {        var _this = $(this).parent(); //         var _thisIndex = $(this).parents('li').index();        var prizeImg = $('#prize');        if(tree_btn.hasClass('lingqu')){            if(!_this.hasClass('receive') && _this.find('.sapling').length <= 0){                if(isActive){                                                       isActive = false; //防止动作未完成之前触发多次点击事件                                           $.ajax({                        type: 'get',                        url: 'test1.txt',                        data: {                            userId: userId.val(),                            clickNum:clickNum                        },                        dataType: 'json',                        success: function(result) {                            if(result.status == 'succeed') {                                if(result.clickNum == 6 || clickNum == 6 ) {                                    alertShow(tip_repeat02);//alert('一个账户只能玩一次,一次可以植树6次')                                }                                 else {                                    clickNum++;                                    _this.append('<img class="sapling" src="images/egg01-break.png" />');                                    /*_this.find('.sapling').animate({                                        'height': '80',                                        'margin-left': -62.63 / 2                                    }, 500);*/                                    //setTimeout(function(){                                        _this.css('cursor','default');//cursor小树苗                                        //_this.find('.sapling').attr('src',"images/egg01-break.png");                                        _this.find('.sapling').animate({                                            'height': '255',                                            'margin-left': -_this.width() / 2                                        }, 1500);                                    //},500)                                    setTimeout(function() {                                        //$('.sapling_t').hide();//隐藏把绿色还给春天,让红色留给投资!2017一路飘红~~                                        isActive = true; //恢复按钮的点击状态                                        _this.addClass('receive');                                        for(var i = 0; i < randList.length; i++) {                                            alterTips_bg.show();                                            successTip.show();                                             if(_thisIndex == randList[0]) { //判断元素下标是否在随机生成的数组中,有即让其抽奖                                                var random = Math.random();                                                if(random <= 0.05) {                                                prizeImg.attr('src', 'images/prizeImg/gold.png');                                                prizeImg.attr('alt', '足金金蛋吊坠');                                                 $(".font").prepend('足金金蛋吊坠');                                                 } else if(random > 0.05 && random <= 0.15) {                                                prizeImg.attr('src', 'images/prizeImg/pillow.png');                                                prizeImg.attr('alt', '舒适汽车护颈头枕一对');                                                  $(".font").prepend('舒适汽车护颈头枕一对');                                                 } else if(random > 0.15 && random <= 0.8) {                                                prizeImg.attr('src', 'images/prizeImg/mat.png');                                                prizeImg.attr('alt', '户外野餐垫');                                                  $(".font").prepend('户外野餐垫');                                                 } else {                                                prizeImg.attr('src', 'images/prizeImg/gold_b.png');                                                prizeImg.attr('alt', '999金币10个');                                                  $(".font").prepend('999金币10个');                                                 }                                                return false;                                            } else if(_thisIndex == randList[1]) {                                                prizeImg.attr('src', 'images/prizeImg/book.png');                                                prizeImg.attr('alt', '黄金');                                                $(".font").prepend('黄金');                                                 return false;                                            }                                        }                                         alertShow(sorry);                                         successTip.hide();                                         //alert('很遗憾,与大奖擦肩而过!');                                    }, 1500)                                }                            }                                                       },                        error: function() {                            //alert('查询出错')                        }                    })                }            }            else {                if(isActive){                    alertShow(tip_repeat01);                    //alert('游戏虽好,切莫贪玩,奖品已领,下期再会~');                }            }        }        else{            alertShow(notreceived);//还没领树苗~提示        }    }})//关闭弹窗function closeTips() {    alterTips_bg.hide();    alertTips.hide();    $('.egg').show();    $('.breakegg').hide();  //还原 效果}closeButt.on('click', closeTips);  //关闭提示   $('#knowButt').on('click', function() { //关闭重复领奖弹窗    closeTips();    $(this).siblings('.egg').show().siblings('.breakegg').show();});$('#receiveButt').on('click', function() { //领取奖品    closeTips();    $(this).siblings('.egg').show().siblings('.breakegg').show();    $('.alterTips').hide();     alertShow(receiveTip);     $('.breakegg').show(); })

})

//读取中奖名单内容
.ajax({  
    type: “get”,  
    url: “test1.txt”,  
    dataType: ‘json’,  
    /* data: { type: “selectprizepeople”, Soure: document.title },*/  
    success: function(result) {  
        if(result.status == “succeed”) {
.each(result.obj, function(index, data) {
$(‘#winList’).append(‘

  • ’ + GetString(data.UserName) + ‘

    砸中 ’ + data.Prize + ‘

  • ’);
    })
    carouselUp(‘#carouselUp’);
    } else {
    carouselUp(‘#carouselUp’);
    }
    }
    });

    /把查询出来的中奖名单的用户信息截取字段隐藏/
    function GetString(str) {
    if(str != “”) {
    var string = str.substring(0, 1) + ‘*’ + str.substring(2, str.length)
    return string;
    }
    }

    阅读全文
    0 0
    原创粉丝点击