Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 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. <span style="font-family:lora;font-size:50px">
  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.  
  22. function calcage(secs, num1, num2) {
  23. s = ((Math.floor(secs/num1))%num2).toString();
  24. if (LeadingZero && s.length < 2)
  25. s = "0" + s;
  26. return "<b>" + s + "</b>";
  27. }
  28.  
  29. function CountBack(secs) {
  30. if (secs < 0) {
  31. document.getElementById("cntdwn").innerHTML = FinishMessage;
  32. return;
  33. }
  34. DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
  35. DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));
  36. DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));
  37. DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));
  38.  
  39. document.getElementById("cntdwn").innerHTML = DisplayStr;
  40. if (CountActive)
  41. setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
  42. }
  43.  
  44. function putspan(backcolor, forecolor) {
  45. document.write("<span id='cntdwn' style='background-color:" + backcolor +
  46. "; color:" + forecolor + "'></span>");
  47. }
  48.  
  49. if (typeof(BackColor)=="undefined")
  50. BackColor = "white";
  51. if (typeof(ForeColor)=="undefined")
  52. ForeColor= "black";
  53. if (typeof(TargetDate)=="undefined")
  54. TargetDate = "05/18/2017 0:00 AM";
  55. if (typeof(DisplayFormat)=="undefined")
  56. DisplayFormat = "%%D%% : %%H%% : %%M%% : %%S%% ";
  57. if (typeof(CountActive)=="undefined")
  58. CountActive = true;
  59. if (typeof(FinishMessage)=="undefined")
  60. FinishMessage = "";
  61. if (typeof(CountStepper)!="number")
  62. CountStepper = -1;
  63. if (typeof(LeadingZero)=="undefined")
  64. LeadingZero = true;
  65.  
  66.  
  67. CountStepper = Math.ceil(CountStepper);
  68. if (CountStepper == 0)
  69. CountActive = false;
  70. var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
  71. putspan(BackColor, ForeColor);
  72. var dthen = new Date(TargetDate);
  73. var dnow = new Date();
  74. if(CountStepper>0)
  75. ddiff = new Date(dnow-dthen);
  76. else
  77. ddiff = new Date(dthen-dnow);
  78. gsecs = Math.floor(ddiff.valueOf()/1000);
  79. CountBack(gsecs);
  80. </span>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement