azurethemes

Countdown/time widget

Oct 2nd, 2017
1,873
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. CREDIT!! PLEASE PUT THIS SOMEWHERE IN YOUR THEME!!! THANK YOU! :)
  2.  
  3.  
  4. <!----
  5.  
  6.  
  7.  
  8. widget 1 countdown & time
  9. 1 2 0 4 p x . t u m b l r . c o m
  10. © 2017. all rights reserved
  11.  
  12.  
  13.  
  14. --->
  15.  
  16.  
  17.  
  18. STEP 1)
  19. place the following code somewhere after <style type="text/css"> but still before </style>
  20.  
  21. #time_box {
  22. width:120px;
  23. height:88px;
  24. padding:20px;
  25. padding-left:30px;
  26. background:white;
  27. border-radius:0px 0px 3px 3px;
  28. border:1px solid #eeeeee;
  29. left:40px;
  30. box-shadow:0px 2px 3px rgba(0,0,0,.10);
  31. top:30px;
  32. text-align:left;
  33. position:fixed;
  34. }
  35. #time_box b {
  36. font-weight:600;
  37. font-size:10px;
  38. letter-spacing:0px;
  39. text-transform:uppercase;
  40. font-family: 'khula', sans-serif;
  41. }
  42. #clock{
  43. text-align:left;
  44. letter-spacing:1px;
  45. font-size:9px;
  46. font-weight:600;
  47. color:#444444;
  48. font-family: 'khula', sans-serif;
  49. }
  50. #clock_wrap {
  51. display:inline-block;
  52. position:fixed;
  53. font-size:10px;
  54. margin-top:10px;
  55. margin-left:0px;
  56. text-align:left;
  57. }
  58. #countdown {
  59. font-family:'khula', sans-serif;
  60. text-transform:uppercase;
  61. letter-spacing:1px;
  62. font-size:9px;
  63. color:#444444;
  64. font-weight:600;
  65. }
  66. #time_box span {
  67. padding-top:5px;
  68. font-size:7px;
  69. }
  70.  
  71.  
  72.  
  73. STEP 2)
  74. place the following code right beneath </style>
  75.  
  76.  
  77. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
  78. <!-- BELOW IS THE CURRENT TIME SCRIPT: here you don't have to edit anything! do not touch it! -->
  79. <script>
  80. function updateClock() {
  81. var currentTime = new Date();
  82. var currentHours = currentTime.getHours();
  83. var currentMinutes = currentTime.getMinutes();
  84. var currentSeconds = currentTime.getSeconds();
  85.  
  86. var currentDate = currentTime.toDateString();
  87. var currentWeekday = currentDate.substring(0, 3);
  88. var currentMonth = currentDate.substring(4, 8);
  89. var currentYear = currentTime.getFullYear();
  90. var currentDay = currentTime.getDate();
  91.  
  92.  
  93. // Pad the minutes and seconds with leading zeros, if required
  94. currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
  95. currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds;
  96.  
  97. // Choose either "AM" or "PM" as appropriate
  98. var timeOfDay = (currentHours < 12) ? "AM" : "PM";
  99.  
  100. // Convert the hours component to 12-hour format if needed
  101. currentHours = (currentHours > 12) ? currentHours - 12 : currentHours;
  102.  
  103. // Convert an hours component of "0" to "12"
  104. currentHours = (currentHours == 0) ? 12 : currentHours;
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112. // Compose the string for display
  113. var currentTimeString = + currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;
  114.  
  115.  
  116. $("#clock").html(currentTimeString);
  117.  
  118. }
  119.  
  120. $(document).ready(function($) {
  121.  
  122.  
  123. setInterval('updateClock()', 1000);
  124. });
  125. </script>
  126. <!-- BELOW IS THE COUNTDOWN SCRIPT: to edit the countdown, just put the date where your countdown will end. For example, here it's the 24th October 2017. Replace this date with your date! -->
  127. <script>
  128. var countDownDate = new Date("Oct 24, 2017 10:20:00").getTime();
  129.  
  130.  
  131. var x = setInterval(function() {
  132.  
  133.  
  134. var now = new Date().getTime();
  135.  
  136.  
  137. var distance = countDownDate - now;
  138.  
  139.  
  140. var days = Math.floor(distance / (1000 * 60 * 60 * 24));
  141. var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  142. var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  143. var seconds = Math.floor((distance % (1000 * 60)) / 1000);
  144.  
  145.  
  146. document.getElementById("countdown").innerHTML = days + "d " + hours + "h "
  147. + minutes + "m " + seconds + "s ";
  148.  
  149.  
  150. if (distance < 0) {
  151. clearInterval(x);
  152. document.getElementById("countdown").innerHTML = "EXPIRED";
  153. }
  154. }, 1000);
  155. </script>
  156.  
  157.  
  158.  
  159.  
  160.  
  161. STEP 3)
  162. place the following code right after </head><body>
  163.  
  164. <div id="time_box">
  165. <div id="clock_wrap">
  166. <b><span class="sf sf-chevron-right"></span> Current time:</b> <div id="clock"></div></br>
  167. <b><span class="sf sf-chevron-right"></span> USA trip in:</b>
  168. <div id="countdown">
  169. </div>
  170. </div></div>
Advertisement
Add Comment
Please, Sign In to add comment