抽奖大转盘

//大转盘抽奖
     var i, msg, Log, rep;
     var dial_start ={
         index:- 1, //当前转动到哪个位置,起点位置
         count: 0, //总共有多少个位置
         timer: 0, //setTimeout的ID
         speed: 20, //初始转动速度
         times: 0, //转动次数
         cycle: 50, //转动基本次数:至少需要转动多少次再进入抽奖环节
         prize:- 1, //中奖位置
         init: function( Class){ //初始化
             if( $( "."+ Class). find( ".start_li"). length> 0){
                 $dial_start = $( "."+ Class);
                 $units = $dial_start. find( ".start_li");
                 this. obj = $dial_start;
                 this. count = $units. length;
                 $dial_start. find( ".start_li_"+ this. index). find( ".start_mask"). addClass( "active");
            };
        },
         roll: function(){ //转动
             var index = this. index;
             var count = this. count;
             var dial_start = this. obj;
             $( dial_start). find( ".start_li_"+ index). find( ".start_mask"). removeClass( "active");
             index += 1;
             if( index > count- 1){
                 index = 0;
            };
             $( dial_start). find( ".start_li_"+ index). find( ".start_mask"). addClass( "active");
             this. index = index;
             return false;
        },
         stop: function( index){
             this. prize = index;
             return false;
        }
    };
     function roll(){
         dial_start. times += 1;
         dial_start. roll(); //转动过程调用的是dial_start的roll方法,这里是第一次调用初始化
         if ( dial_start. times > dial_start. cycle+ 10 && dial_start. prize== dial_start. index) {
             clearTimeout( dial_start. timer);
             dial_start. prize=- 1;
             dial_start. times= 0;
             click= false;
             clicks = false;
             popTipShow. alert( '', msg, [ '确定'], function( e){
                 var button = $( e. target). attr( 'class');
                 if( button == 'ok'){
                     this. hide();
                 }
            });
             $. ajax({
                 type: "GET",
                 url:Url+ "wap/Award/awardLog",
                 async: true,
                 data:{
                },
                 dataType: "json",
                 success: function( result){
                     if( result. code == 200){
                         Log = result. data;
                         $( ".winners_con"). remove();
                         $( Log). each( function( index, data){
                             $( ".winners"). append( "<div class='winners_con'><span>"+ data[ 'datetime']+ "</span><span>"+ data[ 'awardname']+ "</span></div>");
                        });
                         console. log( result. data);
                    } else{
                         console. log( result. message);
                    }
                }
            });
        } else{
             if ( dial_start. times< dial_start. cycle) {
                 dial_start. speed -= 10;
            } else if( dial_start. times== dial_start. cycle) {
                     dial_start. prize = i- 1;
            } else{
                 if ( dial_start. times > dial_start. cycle+ 10 && (( dial_start. prize== 0 && dial_start. index== 7) || dial_start. prize== dial_start. index+ 1)) {
                     dial_start. speed += 110;
                } else{
                     dial_start. speed += 20;
                }
            }
             if ( dial_start. speed< 40) {
                 dial_start. speed= 40;
            };
             dial_start. timer = setTimeout( roll, dial_start. speed); //循环调用
        }
         return false;
    };
     var click= false;
     var clicks = false;
     window. onload= function(){
         $( "#start_open"). click( function(){
             if( click == false){
                 $. ajax({
                     type: "GET",
                     url:Url+ "wap/Award/award",
                     async: true,
                     data:{
                    },
                     dataType: "json",
                     success: function( result){
                         if( result. code == 200){
                             rep = result[ 'data'][ 'repository'];
                             popTipShow. alert( '', "已消耗"+ rep+ "个葡萄", [ '确定'], function( e){
                                 var button = $( e. target). attr( 'class');
                                 if( button == 'ok'){
                                     this. hide();
                                 }
                            }); 
                             ware();
                             i = result[ 'data'][ 'rid'];
                             dial_start. init( 'dial_start');
                             msg = result. message;
                        } else if( result. code == 0){
                             popTipShow. alert( '', result. message, [ '确定'], function( e){
                                 var button = $( e. target). attr( 'class');
                                 if( button == 'ok'){
                                     this. hide();
                                 }
                            }); 
                        } else if( result. code == - 1){
                             //能否抽奖
                             popTipShow. alert( '', result. message, [ '确定'], function( e){
                                 var button = $( e. target). attr( 'class');
                                 if( button == 'ok'){
                                     this. hide();
                                 }
                            });
                             click = true;
                        }
                    }
                });
            };
             if ( click) { //click控制一次抽奖过程中不能重复点击抽奖按钮,后面的点击不响应
                 return false;
            } else{
                 dial_start. speed= 100;
                 roll(); //转圈过程不响应click事件,会将click置为false
                 click= true; //一次抽奖完成后,设置click为true,可继续抽奖
                 clicks = true;
                 return false;
            };
        });
    };


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值