index_change.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. var ChangeNum = {
  2. dom: "cumulative",
  3. clkCls: "number_box",
  4. clkUnitCls: "unit",
  5. clkTopCls: "top",
  6. clkBtmCls: "btm",
  7. fCls: "add_f",
  8. wCls: "add_w",
  9. change_c: '',
  10. old_quota: '',
  11. quota: '',
  12. ClkUnit: function (val, minVal, maxVal, oCls) {
  13. arguments[3] || (oCls = ""),
  14. this.update = function () {
  15. this.updateTxt(),
  16. this.val > this.maxVal && (this.setVal(this.minVal), this.period()),
  17. this.val < this.minVal && (this.setVal(this.maxVal), this.period())
  18. },
  19. this.incVal = function () {
  20. this.val++,
  21. this.update()
  22. },
  23. this.decVal = function () {
  24. this.val--,
  25. this.update()
  26. },
  27. this.updateTxt = function () {
  28. this.val > 9 ? this.text = this.val : this.text = this.val
  29. },
  30. this.setVal = function (v) {
  31. this.val = v,
  32. this.updateTxt()
  33. },
  34. this.pane = document.createElement("div"),
  35. this.pane.className = ChangeNum.clkUnitCls + " " + oCls,
  36. this.setVal(val),
  37. this.minVal = minVal,
  38. this.maxVal = maxVal,
  39. this.topbak = document.createElement("div"),
  40. this.topbak.txt = document.createElement("span"),
  41. this.topbak.className = ChangeNum.clkTopCls,
  42. this.topfnt = document.createElement("div"),
  43. this.topfnt.txt = document.createElement("span"),
  44. this.topfnt.className = ChangeNum.clkTopCls,
  45. this.btmbak = document.createElement("div"),
  46. this.btmbak.txt = document.createElement("span"),
  47. this.btmbak.className = ChangeNum.clkBtmCls,
  48. this.btmfnt = document.createElement("div"),
  49. this.btmfnt.txt = document.createElement("span"),
  50. this.btmfnt.className = ChangeNum.clkBtmCls,
  51. this.pane.appendChild(this.topbak),
  52. this.topbak.appendChild(this.topbak.txt),
  53. this.pane.appendChild(this.topfnt),
  54. this.topfnt.appendChild(this.topfnt.txt),
  55. this.pane.appendChild(this.btmbak),
  56. this.btmbak.appendChild(this.btmbak.txt),
  57. this.pane.appendChild(this.btmfnt),
  58. this.btmfnt.appendChild(this.btmfnt.txt),
  59. this.mtx = !1,
  60. this.animateReset = function () {
  61. ChangeNum.transform(this.btmfnt, ""),
  62. ChangeNum.transform(this.btmbak, ""),
  63. this.btmfnt.txt.innerHTML = this.text,
  64. this.topbak.txt.innerHTML = this.text,
  65. this.topfnt.txt.innerHTML = this.text,
  66. this.btmbak.txt.innerHTML = this.text,
  67. ChangeNum.transform(this.topfnt, ""),
  68. ChangeNum.transform(this.topbak, "")
  69. },
  70. this.period = null,
  71. this.turnDown = function (v) {
  72. var u = this;
  73. if (!this.mtx) {
  74. this.setVal(v);
  75. var topDeg = 0,
  76. btmDeg = 90;
  77. this.topbak.txt.innerHTML = this.text,
  78. ChangeNum.transform(u.topfnt, "rotateX(0deg)");
  79. var timer1 = setInterval(function () {
  80. if (ChangeNum.transform(u.topfnt, "rotateX(" + topDeg + "deg)"), topDeg -= 10, -90 >= topDeg) {
  81. ChangeNum.transform(u.topfnt, "rotateX(0deg)"),
  82. u.topfnt.txt.innerHTML = u.text,
  83. ChangeNum.transform(u.btmfnt, "rotateX(90deg)"),
  84. u.btmfnt.txt.innerHTML = u.text;
  85. var timer2 = setInterval(function () {
  86. 0 >= btmDeg && (clearInterval(timer2), u.animateReset(), u.mtx = !1),
  87. ChangeNum.transform(u.btmfnt, "rotateX(" + btmDeg + "deg)"),
  88. btmDeg -= 10
  89. },
  90. 30);
  91. clearInterval(timer1)
  92. }
  93. },
  94. 30)
  95. }
  96. },
  97. this.animateReset()
  98. },
  99. Clock: function (prt, quota) {
  100. $("#" + ChangeNum.dom).html("");
  101. this.pane = document.createElement("div"),
  102. this.pane.className = ChangeNum.clkCls;
  103. var arr = new Array,
  104. str_arr = ChangeNum.quota.toString().split(""),
  105. bit = str_arr.length,
  106. mod = bit % 3,
  107. w = 60 * bit + 20 * parseInt(bit / 3) + 8 * (bit - parseInt(bit / 3));
  108. 0 == mod && (w -= 20);
  109. prt.style.width = w + "px";
  110. for (var i = 0; bit > i; i++) {
  111. var cls = "";
  112. 0 == i ? cls = ChangeNum.fCls : (i - mod) % 3 == 0 && (cls = ChangeNum.wCls),
  113. this.ng = new ChangeNum.ClkUnit(str_arr[i], 0, 9, cls),
  114. arr.push(this.ng),
  115. this.pane.appendChild(this.ng.pane)
  116. }
  117. prt.appendChild(this.pane);
  118. this.timer = null,
  119. this.make = function () {
  120. ChangeNum.quota.length != $("input[name='amount']").val().length && ($("input[name='amount']").val(ChangeNum.quota), $("#" + ChangeNum.dom).html(""), ChangeNum.change_c = new ChangeNum.Clock(document.getElementById("cumulative"), ChangeNum.quota));
  121. var yi = parseInt(ChangeNum.quota / 1e8),
  122. wan = parseInt((ChangeNum.quota - 1e8 * yi) / 1e4),
  123. bi = parseInt(ChangeNum.quota / 1e9),
  124. mi = parseInt((ChangeNum.quota - 1e9 * bi) / 1e6);
  125. if (yi > 0) {
  126. $(".yiyi1").show();
  127. $(".yiyi2").show();
  128. }
  129. $("#yi").html(yi),
  130. $("#wan").html(wan),
  131. $("#bi").html(bi),
  132. $("#mi").html(mi);
  133. var old_str_arr = ChangeNum.old_quota.toString().split("");
  134. var str_arr = ChangeNum.quota.toString().split("");
  135. for (var i = str_arr.length - 1; i >= 0; i--) {
  136. if (old_str_arr[i] != str_arr[i]) {
  137. arr[i].turnDown(str_arr[i])
  138. }
  139. }
  140. ChangeNum.old_quota = ChangeNum.quota;
  141. },
  142. this.start = function () {
  143. this.make();
  144. var _this = this;
  145. this.timer = setInterval(function () {
  146. _this.make()
  147. },
  148. 5e3)
  149. },
  150. this.pause = function () {
  151. clearInterval(this.timer)
  152. },
  153. this.start()
  154. },
  155. transform: function (obj, tran) {
  156. try {
  157. obj.style.WebkitTransform = tran,
  158. obj.style.MozTransform = tran,
  159. obj.style.msTransform = tran,
  160. obj.style.OTransform = tran,
  161. obj.style.transform = tran
  162. } catch (e) {
  163. }
  164. },
  165. }
  166. window.setInterval(function () {
  167. $.get('/Ajax/allsum?t=' + Math.random(), function (t) {
  168. ChangeNum.quota = t;
  169. ChangeNum.change_c = new ChangeNum.Clock(document.getElementById(ChangeNum.dom), t);
  170. }, 'json');
  171. }, 3000);