balljump.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. var Balljump=function(e,c,t){
  2. var _this=this;
  3. this.SX=["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"];
  4. this.JJ=["春","夏","秋","冬"];
  5. this.FW=["东","南","西","北"];
  6. this.PK3 = ["fangpian", "heitao", "hongtao", "meihua"];
  7. this.PK3Code = ["A","1","2", "3","4","5","6","7","8","9","10","J","Q","K"];
  8. this.ele=e;
  9. this.code=c;
  10. this.time=t;
  11. this.opts=null;
  12. this.interval = null;
  13. this.time1 = null;
  14. this.active = true;
  15. this.updateTime = function (t) {
  16. if (!_this.active) {
  17. return false;
  18. };
  19. var t1 = new Date(t).getTime();
  20. var t2 = new Date().getTime();
  21. if (t2 - t1 > 0) {
  22. //setTimeout(_this.refresh, 3000);
  23. return false;
  24. };
  25. var countdown = formatTime(t);
  26. if (countdown) {
  27. _this.addData("timebox", 0, countdown);
  28. setTimeout(function () { _this.updateTime(t) }, 1000);
  29. }
  30. else {
  31. _this.refresh();
  32. this.time1 = new Date().getTime();
  33. }
  34. };
  35. this.refresh = function () {
  36. if (!_this.active) {
  37. return false;
  38. };
  39. _this.addData("timebox", 0, "开奖中...");
  40. _this.interval = setInterval(_this.balljump, 30);
  41. setTimeout(function () {
  42. //_this.getAjax(function () {
  43. // var countdown = formatTime(_this.opts.NextOpenTime);
  44. // if (!countdown) {
  45. // var time = new Date().getTime();
  46. // clearInterval(_this.interval);
  47. // if (time - _this.time1 <= 20000) {
  48. // _this.refresh();
  49. // }
  50. // else {
  51. // _this.getData();
  52. // this.time1 = null;
  53. // _this.addData("timebox", 0, "等待开奖");
  54. // }
  55. // }
  56. // else {
  57. // clearInterval(_this.interval);
  58. // _this.getData();
  59. // this.time1 = null;
  60. // _this.updateTime(_this.opts.NextOpenTime);
  61. // }
  62. //})
  63. location.reload()
  64. }, 10000)
  65. };
  66. this.getAjax = function (callback) {
  67. if (!_this.active) {
  68. return false;
  69. };
  70. $.ajax({
  71. url: "/Template/_getKjData",
  72. type: "post",
  73. data: {
  74. lotterytype: _this.code,
  75. },
  76. success: function (res) {
  77. var data = JSON.stringify(res);
  78. _this.opts = JSON.parse(data);
  79. if (callback) {
  80. callback();
  81. }
  82. },
  83. error: function (XMLHttpRequest, textStatus, errorThrown) {
  84. setTimeout(function () { _this.getAjax(callback) }, 20000);
  85. }
  86. })
  87. };
  88. this.getData = function () {
  89. if (!_this.active) {
  90. return false;
  91. };
  92. var balls = [];
  93. _this.addData("qishu", 0, _this.opts.Term);
  94. if (_this.opts.LotteryType == "GP_KLPK3_ShanDong") {
  95. for (var i = 0; i < _this.opts.Details.length; i++) {
  96. _this.addData("ball-pk3", i, _this.opts.Details[i].Value);
  97. var className = _this.opts.Details[i].Label;
  98. var pk3list = _this.ele.getElementsByClassName("pk3-list")[i];
  99. var icon = _this.ele.getElementsByClassName("icon-pk3")[i];
  100. pk3list.className = "pk3-list " + className;
  101. icon.className = "iconfont icon-pk3 icon-" + className;
  102. }
  103. }
  104. else {
  105. if (_this.opts.RedBall || _this.opts.RedBall != null) {
  106. for (var i = 0; i < _this.opts.RedBall.length; i++) {
  107. balls.push(_this.opts.RedBall[i]);
  108. }
  109. }
  110. if (_this.opts.BlueBall || _this.opts.BlueBall != null) {
  111. for (var i = 0; i < _this.opts.BlueBall.length; i++) {
  112. balls.push(_this.opts.BlueBall[i]);
  113. }
  114. }
  115. for (var i = 0; i < balls.length; i++) {
  116. _this.addData("ball-list", i, balls[i]);
  117. }
  118. }
  119. _this.lineHeight();
  120. };
  121. this.balljump = function () {
  122. if (!_this.active) {
  123. return false;
  124. };
  125. var redList = _this.ele.getElementsByClassName("red");
  126. if (redList) {
  127. for (var i = 0; i < redList.length; i++) {
  128. _this.addData("red", i, getRandomNum(1, 33));
  129. }
  130. _this.lineHeight(true);
  131. }
  132. var blueList = _this.ele.getElementsByClassName("blue");
  133. if (blueList) {
  134. for (var i = 0; i < blueList.length; i++) {
  135. _this.addData("blue", i, getRandomNum(1, 16));
  136. }
  137. _this.lineHeight(true);
  138. }
  139. var sxList = _this.ele.getElementsByClassName("shengxiao");
  140. if (sxList) {
  141. for (var i = 0; i < sxList.length; i++) {
  142. _this.addData("shengxiao", i, _this.SX[getRandomNum(0, 11)]);
  143. }
  144. _this.lineHeight(true);
  145. }
  146. var jjList = _this.ele.getElementsByClassName("jijie");
  147. if (jjList) {
  148. for (var i = 0; i < jjList.length; i++) {
  149. _this.addData("jijie", i, _this.JJ[getRandomNum(0, 3)]);
  150. }
  151. _this.lineHeight(true);
  152. }
  153. var fwList = _this.ele.getElementsByClassName("fangwei");
  154. if (fwList) {
  155. for (var i = 0; i < fwList.length; i++) {
  156. _this.addData("fangwei", i, _this.FW[getRandomNum(0, 3)]);
  157. }
  158. _this.lineHeight(true);
  159. }
  160. var pk3lists = _this.ele.getElementsByClassName("pk3-list");
  161. if (pk3lists) {
  162. for (var i = 0; i < pk3lists.length; i++) {
  163. _this.action.addData("ball-pk3", i, _this.PK3Code[getRandomNum(0, 12)]);
  164. var className = _this.PK3[getRandomNum(0, 3)];
  165. var pk3list = _this.ele.getElementsByClassName("pk3-list")[i];
  166. var icon = _this.ele.getElementsByClassName("icon-pk3")[i];
  167. pk3list.className = "pk3-list " + className;
  168. icon.className = "iconfont icon-pk3 icon-" + className;
  169. }
  170. }
  171. };
  172. this.lineHeight = function (jump) {
  173. if (!_this.active) {
  174. return false;
  175. };
  176. var newLineheight = 30;
  177. if (jump) {
  178. newLineheight = getRandomNum(10, 50);
  179. }
  180. var balllists = _this.ele.getElementsByClassName("ball-list");
  181. for (var i = 0; i < balllists.length; i++) {
  182. balllists[i].style.lineHeight = newLineheight + "px"
  183. }
  184. };
  185. this.addData = function (className, i, t) {
  186. if (!_this.active) {
  187. return false;
  188. };
  189. _this.ele.getElementsByClassName(className)[i].innerText = t;
  190. };
  191. this.dele = function () {
  192. _this.active=false;
  193. };
  194. _this.updateTime(_this.time);
  195. return this;
  196. }