Files
wnmj/GonghuiWeb/www/m/js/one/lottery.js
2026-02-24 09:25:17 +08:00

78 lines
2.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var lottery_zt=0;
var $lottery = $("#lottery");
var lottery_indexs=-1;//当前转动到哪个位置,起点位置
var lottery_count=$lottery.find(".lottery-unit").length;//总共有多少个位置
var lottery_timer=0; //setTimeout的ID用clearTimeout清除
var lottery_speed=20; //初始转动速度
var lottery_times=0; //转动次数
var lottery_cycle=50; //转动基本次数:即至少需要转动多少次再进入抽奖环节
var lottery_prize=-1; //中奖位置
function rolls(){
$lottery.find(".lottery-unit-"+lottery_indexs).removeClass("active");
lottery_indexs += 1;
if (lottery_indexs>lottery_count-1) {
lottery_indexs = 0;
};
$lottery.find(".lottery-unit-"+lottery_indexs).addClass("active");
return false;
}
function roll(){
lottery_times += 1;
rolls();
if (lottery_times > lottery_cycle+10 && lottery_prize==lottery_indexs) {
clearTimeout(lottery_timer);
lottery_prize=-1;
lottery_times=0;
lottery_zt=0;
$("#djcj_txt").text("点击抽奖");
//$("#lottery_ck").attr("onclick","acj()");
var d = new Date(),str = '';
str = d.getMonth() + 1+'-'+d.getDate()+' '+d.getHours()+':'+d.getMinutes()+':'+d.getSeconds();
$("#lottery_log").prepend("<li>"+nickname+"<br>抽到 "+lottery_prize_yuanbao+"个元宝<br><font color='red'>今天</font> "+str+"</li>");
var ybs = $("#yuanbao").text();
$("#yuanbao").text(parseInt(ybs)+parseInt(lottery_prize_yuanbao));
}else{
if (lottery_times<lottery_cycle) {
lottery_speed -= 10;
}else if(lottery_times==lottery_cycle) {
//var index = Math.random()*(lottery_count)|0;
lottery_prize = lottery_prize_index;
}else{
if (lottery_times > lottery_cycle+10 && ((lottery_prize==0 && lottery_prize_index==7) || lottery_prize==lottery_prize_index+1)) {
lottery_speed += 110;
}else{
lottery_speed += 20;
}
}
if (lottery_speed<40) {
lottery_speed=40;
};
lottery_timer = setTimeout(roll,lottery_speed);
}
}
function acj(){
if(!lottery_zt){
layer.open({type:2,shade:false});
$("#djcj_txt").html("<font color='#999'>抽奖中...</font>");
$.getJSON("/dh/lottery.php?gameid="+gid,function(ret){
//alert(JSON.stringify(ret));
layer.closeAll();
//$("#lottery_ck").removeAttr("onclick");
if(ret.prize){
$("#lottery_game").html(ret.game+"/32");
lottery_speed=100;
lottery_prize_index = ret.prize;
lottery_prize_yuanbao = ret.yuanbao;
roll();
zt++;
}else{
if(ret.error == 'no'){
$("#djcj_txt").html("请先玩游戏");
}else{
$("#djcj_txt").html("请稍后再试");
}
}
});
}
}