Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. /*
  2. Author: Robert Hashemian
  3. http://www.hashemian.com/
  4.  
  5. Use of this code is hereby granted to anyone. No attribution is required.
  6. ********************************************************
  7. Usage Sample:
  8.  
  9. <script language="JavaScript">
  10. TargetDate = "05/18/2017 00:00 AM UTC-0800";
  11. ForeColor = "#FF0000";
  12. BackColor = "rgba(255, 255, 255, 0.05)";
  13. CountActive = true;
  14. CountStepper = -1;
  15. LeadingZero = true;
  16. DisplayFormat = "%%D%% : %%H%% : %%M%% : %%S%% ";
  17. FinishMessage = "It is finally here!";
  18. </script>
  19. */
  20.  
  21. function calcage(secs, num1, num2) {
  22. s = ((Math.floor(secs/num1))%num2).toString();
  23. if (LeadingZero && s.length < 2)
  24. s = "0" + s;
  25. return "<b>" + s + "</b>";
  26. }
  27.  
  28. function CountBack(secs) {
  29. if (secs < 0) {
  30. document.getElementById("cntdwn").innerHTML = FinishMessage;
  31. return;
  32. }
  33. DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
  34. DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));
  35. DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));
  36. DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));
  37.  
  38. document.getElementById("cntdwn").innerHTML = DisplayStr;
  39. if (CountActive)
  40. setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
  41. }
  42.  
  43. function putspan(backcolor, forecolor) {
  44. document.write("<span id='cntdwn' style='background-color:" + backcolor +
  45. "; color:" + forecolor + "'></span>");
  46. }
  47.  
  48. if (typeof(BackColor)=="undefined")
  49. BackColor = "white";
  50. if (typeof(ForeColor)=="undefined")
  51. ForeColor= "black";
  52. if (typeof(TargetDate)=="undefined")
  53. TargetDate = "05/18/2017 0:00 AM";
  54. if (typeof(DisplayFormat)=="undefined")
  55. DisplayFormat = "%%D%% : %%H%% : %%M%% : %%S%% ";
  56. if (typeof(CountActive)=="undefined")
  57. CountActive = true;
  58. if (typeof(FinishMessage)=="undefined")
  59. FinishMessage = "";
  60. if (typeof(CountStepper)!="number")
  61. CountStepper = -1;
  62. if (typeof(LeadingZero)=="undefined")
  63. LeadingZero = true;
  64.  
  65. <span style="font-family:verdana;font-size:20px">
  66. CountStepper = Math.ceil(CountStepper);
  67. if (CountStepper == 0)
  68. CountActive = false;
  69. var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
  70. putspan(BackColor, ForeColor);
  71. var dthen = new Date(TargetDate);
  72. var dnow = new Date();
  73. if(CountStepper>0)
  74. ddiff = new Date(dnow-dthen);
  75. else
  76. ddiff = new Date(dthen-dnow);
  77. gsecs = Math.floor(ddiff.valueOf()/1000);
  78. CountBack(gsecs);
  79. </span>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement