1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- function LotteryDraw(obj, callback) {
- this.timer = null;
- this.startIndex = obj.startIndex-1 || 0;
- this.count = 0;
- this.winingIndex = obj.winingIndex || 0;
- this.totalCount = obj.totalCount || 6;
- this.speed = obj.speed || 100;
- this.domData=obj.domData;
- this.rollFn();
- this.callback = callback;
- }
- LotteryDraw.prototype = {
- rollFn: function() {
- var that = this;
-
-
- this.startIndex++;
-
-
- if (this.startIndex >= this.domData.length - 1) {
- this.startIndex = 0;
- this.count++;
- }
-
-
- if (this.count >= this.totalCount && this.startIndex === this.winingIndex) {
- if (typeof this.callback === 'function') {
- setTimeout(function() {
- that.callback(that.startIndex,that.count);
- }, 400);
- }
- clearInterval(this.timer);
- }else {
- if (this.count >= this.totalCount - 1) {
- this.speed += 30;
- }
- this.timer = setTimeout(function() {
- that.callback(that.startIndex,that.count);
- that.rollFn();
- }, this.speed);
- }
- }
- }
- module.exports = LotteryDraw;
|