1.首先,得下载jquery.slotmachine.js的文件引入
2.调用:
var machine1 = $(".machine1").slotMachine({
active : 0,
delay : 500
});
var machine2 = $(".machine2").slotMachine({
active : 0,
delay : 500
});
var machine3 = $(".machine3").slotMachine({
active : 0,
delay : 500
});
//其中active代表的是初始化显示第几个,delay代表的是延迟
function onComplete(active){
switch(this.element[0].id){
case 'machine1':
//在这里可以显示出对应到的索引
break;
case 'machine2':
break;
case 'machine3':
break;
}
}
machine1.shuffle(8, onComplete, 2);
setTimeout(function(){
machine2.shuffle(8, onComplete, 2);
}, 500);
setTimeout(function(){
machine3.shuffle(8, function(){
//抽奖结果出来之后调用
},2);
}, 1000);
//其中2是指中奖的结果,就抽奖结果将为索引为2
//其实上面讲述的这些网上很多都有说到过,例如https://www.cnblogs.com/wdlblog/p/6593947.html
3.问题(重点,不一样的地方):直接npm或者在网上下载的jquery.slotmachine.js中的中奖概率都是随机的,但大家要的效果肯定是想控制中奖结果的。
解决