javascript九宫格抽奖

【前言】

特点:兼容好原生插件体积小无依赖

方法:

  • 1 run(number,function(){}) 获奖;
  • 2 running(function(){}) 无限转圈;
  • 3 runningStop() 停止无限转圈。

html:

1
<script type="text/javascript" src="plug.lottery.js" charset="utf-8"></script>

插件git地址

初始化:

1
2
3
4
5
6
Lottery.init({
classChild: "lottery-li", //抽奖元素类名前缀 例如:class="lottery-unit lottery-unit-1"
classOn: "select-on", //抽奖元素高亮样式类名
loop: 3, //初始旋转圈数
speed: 100 //初始速度
});

同步抽奖:

1
2
3
4
5
6
Lottery.run(2,  //抽中第几个, 必须为数字
function () {
//这里是回调函数的内容
console.log('中奖');
}
);

异步抽奖:

1
2
3
4
5
6
7
8
Lottery.running(function () {          //无限匀速转动
$.get('xxxx',{},function (res) {
Lottery.runningStop(); //停止转动
Lottery.run(2, function () { //抽奖结构
console.log('中奖');
});
});
});

关于作者