这是公司年会抽奖的一个程序,其中特等奖,1等奖,2等奖设置了12个空格符占位,目的是为了让刚到不久的员工排除在外,又不让他们看到,怎么让程序不抽到这12个空格,请教了一个6年的老司机,没搞定,哪位前端大神帮忙看下,按空格键执行程序,谢谢
演示地址:
http://software.gsi.com.cn/test/
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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | //lottery title var lotteryTitles = ['特等奖1名','一等奖1名', '二等奖2名', '三等奖3名','四等奖10名','五等奖12名','六等奖15名','参与奖17名']; //lottery prefix var lotteryPrefixes = ['special','first', 'second', 'third','fourth','fifth','sixth','participate']; //first,second,third and fourth prize var members = [ //special //0012,0013,0021,0027,0028,0029,0030,0031,0032,0034,0036,0037,0038, [ '0001','0002','0003','0004','0005','0006','0007','0008','0009','0010', '0011','0014','0015','0016','0017','0018','0019','0020','0022','0023', '0024','0025','0026','0027','0033','0035','0039','0040','','','','','', '','','','','','','', '0041','0042','0043','0044','0045','0046','0047','0048','0049','0050', '0051','0052','0053','0054','0055','0056','0057','0058','0059','0060', ], //One [ '0001','0002','0003','0004','0005','0006','0007','0008','0009','0010', '0011','0014','0015','0016','0017','0018','0019','0020','0022','0023', '0024','0025','0026','0027','0033','0035','0039','0040','','','','','', '','','','','','','', '0041','0042','0043','0044','0045','0046','0047','0048','0049','0050', '0051','0052','0053','0054','0055','0056','0057','0058','0059','0060', ], //Two [ '0001','0002','0003','0004','0005','0006','0007','0008','0009','0010', '0011','0014','0015','0016','0017','0018','0019','0020','0022','0023', '0024','0025','0026','0027','0033','0035','0039','0040','','','','','', '','','','','','','', '0041','0042','0043','0044','0045','0046','0047','0048','0049','0050', '0051','0052','0053','0054','0055','0056','0057','0058','0059','0060', ], //three [ '0001','0002','0003','0004','0005','0006','0007','0008','0009','0010', '0011','0012','0013','0014','0015','0016','0017','0018','0019','0020', '0021','0022','0023','0024','0025','0026','0027','0028','0029','0030', '0031','0032','0033','0034','0035','0036','0037','0038','0039','0040', '0041','0042','0043','0044','0045','0046','0047','0048','0049','0050', '0051','0052','0053','0054','0055','0056','0057','0058','0059','0060', ], //four [ '0001','0002','0003','0004','0005','0006','0007','0008','0009','0010', '0011','0012','0013','0014','0015','0016','0017','0018','0019','0020', '0021','0022','0023','0024','0025','0026','0027','0028','0029','0030', '0031','0032','0033','0034','0035','0036','0037','0038','0039','0040', '0041','0042','0043','0044','0045','0046','0047','0048','0049','0050', '0051','0052','0053','0054','0055','0056','0057','0058','0059','0060', ], //five [ '0001','0002','0003','0004','0005','0006','0007','0008','0009','0010', '0011','0012','0013','0014','0015','0016','0017','0018','0019','0020', '0021','0022','0023','0024','0025','0026','0027','0028','0029','0030', '0031','0032','0033','0034','0035','0036','0037','0038','0039','0040', '0041','0042','0043','0044','0045','0046','0047','0048','0049','0050', '0051','0052','0053','0054','0055','0056','0057','0058','0059','0060', ], //Six [ '0001','0002','0003','0004','0005','0006','0007','0008','0009','0010', '0011','0012','0013','0014','0015','0016','0017','0018','0019','0020', '0021','0022','0023','0024','0025','0026','0027','0028','0029','0030', '0031','0032','0033','0034','0035','0036','0037','0038','0039','0040', '0041','0042','0043','0044','0045','0046','0047','0048','0049','0050', '0051','0052','0053','0054','0055','0056','0057','0058','0059','0060', ], //Join [ '0001','0002','0003','0004','0005','0006','0007','0008','0009','0010', '0011','0012','0013','0014','0015','0016','0017','0018','0019','0020', '0021','0022','0023','0024','0025','0026','0027','0028','0029','0030', '0031','0032','0033','0034','0035','0036','0037','0038','0039','0040', '0041','0042','0043','0044','0045','0046','0047','0048','0049','0050', '0051','0052','0053','0054','0055','0056','0057','0058','0059','0060', ], ]; var bodyWidth = $("body").css("width"); $("div.items").css("width",(bodyWidth.substring(0,bodyWidth.length-2)-380)+"px"); //跑马灯循环 var tx; var runtx; //是否正在运行跑马灯 var isRun=true; //是否跑马灯暂停状态 var pause =false; //排名分组显示算法已经取消 //var ts=20 //默认跑马灯频率 var pl=10; //程序是否开始运行用于判断程序是否开始运行 var isStart=false; var zzs = "#98ff98"; //跑马灯音效 var runingmic=document.getElementById("runingmic"); runingmic.volume=0.5; //中奖音效 var pausemic=document.getElementById("pausemic"); pausemic.volume=1.0; var keyStatus=false; //帮助对象 var readmeDialog = showReadme(); $("document").ready(function(){ //初始化皮肤 if(localStorage.getItem(lotteryPrefix+"pf")) { var pf = localStorage.getItem(lotteryPrefix+"pf"); dynamicLoading.css("./css/style"+pf+".css"); $("#bodybg img").attr("src","./images/bodybg"+pf+".jpg"); $("input[name=pf][value="+pf+"]").attr("checked",true); if(pf!=1){ zzs="#ba3030"; } } //初始化标题 if(localStorage.getItem("title")) { $("#title").val(localStorage.getItem("title")); } $(".top").html($("#title").val()+" "+"("+lotteryTitles[lotteryNumber]+")"); //频率模式本地存储 if(localStorage.getItem(lotteryPrefix+"ms")) { pl = localStorage.getItem(lotteryPrefix+"ms"); $("input[name=ms][value="+pl+"]").attr("checked",true); } //排名信息本地存储 if(localStorage.getItem(lotteryPrefix+"sequence")) { var ssHtml = localStorage.getItem(lotteryPrefix+"sequence"); $(".ss").html(ssHtml); } //custom lottery var customLotteryMembers = ['159*1059', '152*9392']; //创建item小方格 $.each(members, function(index, value){ if($.inArray(value, customLotteryMembers) >= 0) { customers.push(index); } var lm = []; $.each(lotteryPrefixes, function(index, value){ var temp = localStorage.getItem(value+"lotteryMembers"); if(temp) { lm = $.merge(lm, temp.split(',')); } }); var ignoreClassName = ''; if($.inArray(value, lm) >= 0) { ignoreClassName = ' ignore'; } $("div.items").append(" "+(++index)+" ");}); //本地存储item宽度信息 if(localStorage.getItem(lotteryPrefix+"itemk")) { $("div.item").css("width",localStorage.getItem(lotteryPrefix+"itemk")+"px"); } //本地存储item高度信息 if(localStorage.getItem(lotteryPrefix+"itemg")) { $("div.item").css("height",localStorage.getItem(lotteryPrefix+"itemg")+"px"); $("div.item").css("line-height",localStorage.getItem(lotteryPrefix+"itemg")+"px"); } //回显设定item宽高 $("#itemk").attr("placeholder",$(".i1").css("width")); $("#itemg").attr("placeholder",$(".i1").css("height")); //初始化排序信息 $(".ss li").each(function(idx,item){ var num = $(item).attr("number"); $(".i"+num).addClass("ignore"); lotteryMembers.push(members[num]); localStorage.setItem(lotteryPrefix+"lotteryMembers", lotteryMembers); }); $("body").keyup(function(e){ keyStatus = false; }); //全局键盘事件监听 $("body").keydown(function(e){ if(isStart){ if(! keyStatus) { keyStatus=true; } else { return false; } } if(e.keyCode == 116 || e.keyCode == 8) { return true; } //按F1弹出帮助窗口 if(e.keyCode == 112) { e.preventDefault(); if($(".readme:hidden").size() > 0) readmeDialog.show(); else readmeDialog.close(); return false; } //ESC案件呼出隐藏菜单 if(e.keyCode == 27) { if($(".help:hidden").size() > 0) $(".help").show(); else $(".help").hide(); return false; } if(e.keyCode == 37) { $(".prev").click(); return false; } if(e.keyCode == 39) { $(".next").click(); return false; } //当程序出于暂停状态 if(pause) { //以下按键有效 数字键 0-9 和 小键盘 0-9 return true; } //存在未中奖用户切程序出于未开始运行状态执行开始方法 if((e.keyCode==32 || e.keyCode == 65) && $("div.item:not(.ignore)").size() != 0 && ! isStart) { isStart = !isStart; startApp(); return false; } if(e.keyCode == 32 || e.keyCode == 65) { //当所有抽奖号全部抽取完毕则销毁跑马和音效循环 if($("div.item:not(.ignore)").size() == 0) { clearInterval(tx); clearInterval(runtx); runingmic.puase(); alert("抽奖已经全部结束。"); return false; } //更新运行状态 isRun = !isRun; //如果项目出于运行状态 if(! isRun) { //deal customers var runCount = $(".ss>ol>li").size(); if(runCount >= 1 && lotteryNumber <2 && customers.length > 0) { var randCustomer = Math.floor(Math.random() * customers.length); if($(".i"+customers[randCustomer]+".ignore").attr('index') != customers[randCustomer]) { $(".item.active").removeClass("active"); $("div.item:not(.ignore):not(.active).i"+customers[randCustomer]).addClass("active"); customers.splice(randCustomer, 1); } } //取得当前选中号码 var it = $(".item.active").attr('index'); //停止跑马灯 runingmic.pause(); //播放中奖音效 pausemic.currentTime = 0; pausemic.play(); //中奖号处理 var it = Number(it); $('.ss ol').append(' var dd = dialog({ title: '抽奖结果', content: ' '+members[it]+' 恭喜您,抽得'+lotteryTitle+'!',okValue: '确定', width:'1885', height:'850', ok: function(){ dd.close(); } }); dd.show(); lotteryMembers.push(members[it]); localStorage.setItem(lotteryPrefix+"lotteryMembers", lotteryMembers); localStorage.setItem(lotteryPrefix+"sequence",$(".ss").html()); $(".item.active").addClass("ignore"); $(".item.active").pulsate({ color: zzs, //#98ff98 repeat: 5 }); } else { $(".active").removeClass("active"); runingmic.play(); } } e.preventDefault(); }); //打开高级设置窗口 $("a.config").click(function(){ pause=true; runingmic.pause(); var d = dialog({ title: '抽奖参数设定', content: $(".model"), okValue: '确定', ok: function(){ if($("#reset:checked").val() && confirm("点击确定将清空抽奖结果。")){ localStorage.removeItem(lotteryPrefix+"sequence"); localStorage.removeItem(lotteryPrefix+"lotteryMembers"); } if($("#itemk").val()){ localStorage.setItem(lotteryPrefix+"itemk", $("#itemk").val()); } if($("#itemg").val()){ localStorage.setItem(lotteryPrefix+"itemg", $("#itemg").val()); } localStorage.setItem("title", $("#title").val()); localStorage.setItem(lotteryPrefix+"ms", $("input[name=ms]:checked").val()); localStorage.setItem(lotteryPrefix+"pf", $("input[name=pf]:checked").val()); window.location.reload(); }, onclose: function(){ pause = false; } }); d.show(); }); //清除错误中奖号 $("body").on("click",".item.ignore",function(){ if(confirm("点击确定将清除错误中奖号。")) { $("li[number="+$(this).attr('index')+"]").remove(); $(this).removeClass("active ignore"); localStorage.setItem(lotteryPrefix+"sequence",$(".ss").html()); localStorage.removeItem(lotteryPrefix+"lotteryMembers"); } else { } }); }); //程序开始入口 function startApp(){ //开始播放跑马灯音效 runingmic.play(); //产生随机数临时变量 var rand = 0; //存储上一次随机数的临时变量 var prenum; tx = setInterval(function(){ if(isRun){ while(true){ rand=Math.floor(Math.random() * ( $("div.item:not(.ignore)").size())); if(rand == 0 || rand != prenum){break;} } prenum = rand; $(".item.active").removeClass("active"); $("div.item:not(.ignore):not(.active)").eq(rand).addClass("active"); } }, pl); runtx = setInterval(function(){runingmic.currentTime = 0;},1000); } /** * 显示帮助信息 * * @returns dialog */ function showReadme() { return dialog({ title: '帮助信息', content: $(".readme") , width:'400px', okValue: '关闭', ok:function(){ }, onclose: function () { pause=false; } }); } var dynamicLoading = { css: function(path){ if(!path || path.length === 0){ throw new Error('argument "path" is required !'); } var head = document.getElementsByTagName('head')[0]; var link = document.createElement('link'); link.href = path; link.rel = 'stylesheet'; link.type = 'text/css'; head.appendChild(link); }, js: function(path){ if(!path || path.length === 0){ throw new Error('argument "path" is required !'); } var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.src = path; script.type = 'text/Javascript'; head.appendChild(script); } } |