1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
| var click=false; var luck={
index: 0, count: 0, timer: 0, speed: 30, times: 0, cycle: 70, prize: -1,
init:function(id){ if ($("#"+id).find(".luck-unit").length>0) { $luck = $("#"+id); $units = $luck.find(".luck-unit"); this.obj = $luck; this.count = $units.length; }; }, roll:function(){ var index = this.index; var count = this.count; var luck = this.obj; $(luck).find(".luck-unit-"+index).removeClass("active"); index += 1; if (index>count-1) { index = 0; }; $(luck).find(".luck-unit-"+index).addClass("active"); this.index=index; return false; }, stop:function(index){ this.prize=index; return false; } };
function roll(which){ luck.times += 1; luck.roll();
if (luck.times > luck.cycle+10 && luck.prize==luck.index) { var title = ''; var content = ''; var desc = ''; var prize = ''; clearTimeout(luck.timer); luck.prize=-1; luck.times=0; click=false;
switch(which) { case 0: prize = '小米鼠标'; break; case 1: prize = '固态硬盘'; break; case 2: prize = '乐扣保温杯'; break; case 3: prize = '京东券'; break; case 4: prize = '谢谢参与'; break; case 5: prize = '万用表'; break; case 6: prize = '摩尔吧课程折扣券'; break; case 7: prize = '小米耳机'; break; }
if(which == 4) { title = '谢谢参与'; content = '再接再厉' desc = '请查看活动详情,获取更多抽奖资格'; } else { title = '恭喜您'; content = '获得 <span class="blue">'+ prize +'</span>'; if(which == 6) { desc = '请至您的”个人中心“查收'; } else { desc = '奖品将于活动结束后统一发送'; } } setTimeout(function() { modalShow(title,content,desc); }, 800); } else { if (luck.times<luck.cycle) { luck.speed -= 10; } else if (luck.times==luck.cycle) { luck.prize = which; } else { if (luck.times > luck.cycle+10 && ((luck.prize==0 && luck.index==7) || luck.prize==luck.index+1)) { luck.speed += 110; } else { luck.speed += 20; } }
if (luck.speed<40) { luck.speed=40; }
luck.timer = setTimeout(function() { roll(which); },luck.speed); } return false; }
$(function() {
luck.init('luckArea');
$("#startBtn").click(function(){ if(click) { return false; }else{ click=true; luck.speed=100; $.get("http://www.moore8.com/campaign/lotteryAct", function (data) { var data = $.parseJSON(data); console.log('data:', data); if(data.code == 1) { var which = data.type; roll(which); } else { if(data.msg == '请先登录!') { loginFunc('course_gift'); } else { var desc = '请查看活动详情,获取更多抽奖资格'; modalShow('对不起', data.msg, desc); } click = false; } }); return false; } }); })
function modalShow(title, body, desc) { var title = title || '温馨提示'; var body = body || ''; var desc = desc || ''; $('#mTitle').html(title); $('#mBody').html(body); $('#mDesc').html(desc); $('#myModal').modal('show'); }
function loginFunc(id) { var href = window.location.href; var id = id ? "%23" + id : ''; window.location.href = "/login/?referer=" + href + id; }
|