JS代码
$(document).ready(function () {
$("#mesBox").hide();
var click = 1; //控制在一次抽奖结束前下次点击无效
var index; //控制的抽奖结束后效果的还原
$(".choujiang").click(function () {
//进行判断是否抽奖完毕
if (click != 1) {
return;
}
click++;
//抽奖完后将图片还原到初始状态
if (index != 1) {
$("#img1").attr("src", "images/1.jpg");
$("#img" + index).attr("src", "images/" + index + index + ".jpg");
}
var i = 1; //图片轮播的地方
var T = 1; //控制转了多少圈才停下来的变量
var math = Math.floor(Math.random() * 100);//此处纯js,所以随便写的概率
var time = setInterval(function () {
i++;
//控制图片轮播的范围(10张图片)
if (i > 10) {
i = 1;
T++;
};
index = i;
//此处为图片的滚动
if (i == 1) {
$("#img10").attr("src", "images/1010.jpg");
}
$("#img" + i).attr("src", "images/" + i + ".jpg");
$("#img" + (i * 1 - 1)).attr("src", "images/" + (i * 1 - 1) + (i * 1 - 1) + ".jpg");
//当滚动5圈后开始出奖
if (T == 5) {
//概率
if (math == 0) {
//在第几个图片停下来(下面以此类推)
if (i == 1) {
clearInterval(time);
click = 1;
$("#mesBox").show()
$("#text").html("恭喜你中奖了!,不过这是假的!");
}
}
if (math == 1 || math == 2) {
if (i == 2) {
clearInterval(time);
click = 1;
$("#mesBox").show()
$("#text").html("恭喜你中奖了!,不过这是假的!");
}
}
if (math == 3 || math == 4 || math == 5) {
if (i == 3) {
clearInterval(time);
click = 1;
$("#mesBox").show()
$("#text").html("恭喜你中奖了!,不过这是假的!");
}
}
if (math == 6 || math == 7 || math == 8) {
if (i == 4) {
clearInterval(time);
click = 1;
$("#mesBox").show()
$("#text").html("恭喜你中奖了!,不过这是假的!");
}
}
if (math >= 9 && math <= 40) {
if (i == 5) {
clearInterval(time);
click = 1;
$("#mesBox").show()
$("#text").html("恭喜你获得10点成长值!");
}
}
if (math >= 41 && math <= 45) {
if (i == 6) {
clearInterval(time);
click = 1;
$("#mesBox").show()
$("#text").html("恭喜你中奖了!,不过这是假的!");
}
}
if (math >= 46 && math <= 50) {
if (i == 7) {
clearInterval(time);
click = 1;
$("#mesBox").show()
$("#text").html("恭喜你中奖了!,不过这是假的!");
}
}
if (math >= 51 && math <= 90) {
if (i == 8) {
clearInterval(time);
click = 1;
$("#mesBox").show()
$("#text").html("谢谢参与,下次中大奖!");
}
}
if (math >= 91 && math <= 95) {
if (i == 9) {
clearInterval(time);
click = 1;
$("#mesBox").show()
$("#text").html("恭喜你中奖了!,不过这是假的!");
}
}
if (math >= 96 && math <= 99) {
if (i == 10) {
clearInterval(time);
click = 1;
$("#mesBox").show()
$("#text").html("恭喜你中奖了!,不过这是假的!");
}
}
}
}, 200)
});
$("input[type=button]").click(function () {
$("#mesBox").hide();
})
});