time.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. function recordTimeObj(){
  2. var s = null, t1 = null, t2 = null;
  3. function recordTime(str, callBack){
  4. var time = 15;
  5. function start(){
  6. var i = 0;
  7. var j = 0;
  8. var count = 0;
  9. var MM = 0;
  10. var SS = time - 1;
  11. var MS = 9;
  12. var totle = (MM + 1) * time * 10;
  13. var d = 180*(MM+1);
  14. MM = "0" + MM;
  15. function showTime(){
  16. totle = totle - 1;
  17. if(totle==0){
  18. clearInterval(s);
  19. clearInterval(t1);
  20. clearInterval(t2);
  21. $(".pie2").css("-o-transform","rotate(" + d + "deg)");
  22. $(".pie2").css("-moz-transform","rotate(" + d + "deg)");
  23. $(".pie2").css("-webkit-transform","rotate(" + d + "deg)");
  24. callBack && callBack();
  25. }else{
  26. if(totle>0 && MS>0){
  27. MS = MS - 1;
  28. if(MS < 10){MS = "0" + MS};
  29. };
  30. if(MS == 0 && SS>0){
  31. MS = 10;
  32. SS = SS - 1;
  33. if(SS < 10){SS = "0" + SS};
  34. };
  35. if(SS==0 && MM>0){
  36. SS = 60;
  37. MM = MM - 1;
  38. if(MM < 10){MM = "0" + MM};
  39. };
  40. };
  41. $(".time span").html( SS + "." + MS);
  42. };
  43. function start1(){
  44. i = i + 360/((time)*10); //
  45. count = count + 1;
  46. if(count >= (time/2*10)){ //
  47. count = 0;
  48. clearInterval(t1);
  49. t2 = setInterval(function(){
  50. start2()
  51. },100);
  52. };
  53. $(".pie1").css("-o-transform","rotate(" + i + "deg)");
  54. $(".pie1").css("-moz-transform","rotate(" + i + "deg)");
  55. $(".pie1").css("-webkit-transform","rotate(" + i + "deg)");
  56. };
  57. function start2(){
  58. j = j + 360/((time)*10); //
  59. count = count + 1;
  60. if(count >= (time/2*10)){ //
  61. count = 0;
  62. clearInterval(t2);
  63. t1 = setInterval("start1()",100);
  64. };
  65. $(".pie2").css("-o-transform","rotate(" + j + "deg)");
  66. $(".pie2").css("-moz-transform","rotate(" + j + "deg)");
  67. $(".pie2").css("-webkit-transform","rotate(" + j + "deg)");
  68. };
  69. s = setInterval(function(){
  70. showTime()
  71. },100);
  72. t1 = setInterval(function(){
  73. start1()
  74. },100);
  75. }
  76. if(str == 'start'){
  77. start();
  78. }else if(str == 'stop'){
  79. clearInterval(s);
  80. clearInterval(t1);
  81. s = null;
  82. t1 = null;
  83. if(t2 != null){
  84. clearInterval(t2);
  85. t2 = null;
  86. }
  87. }
  88. }
  89. return {
  90. recordTime: recordTime
  91. }
  92. }