Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang = "en">
  3. <head>
  4. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  5. </head>
  6. <body>
  7. Hours<br>
  8. <select id="hours"></select> <br>
  9. Minutes<br>
  10. <select id="minutes"></select> <br>
  11. Seconds<br>
  12. <select id="seconds"></select>
  13. <br> <br>
  14. <button id="start">Start!</button>
  15. <button id="stop">Stop!</button>
  16. <br> <br>
  17. <button id="pause">Pause!</button>
  18. <button id="continue">Continue!</button>
  19. <p id="out"></p>
  20.  
  21. <script>
  22. var intervalID, seconds, minutes, hours, now, countdown;
  23.  
  24. $(document).ready(fillSeconds);
  25. $(document).ready(addClickEvents);
  26.  
  27. function addClickEvents() {
  28. document.getElementById("start").addEventListener("click", function(){
  29. captureTime();
  30. startCountdown();
  31. $("#start").prop("disabled", true);
  32. });
  33. document.getElementById("stop").addEventListener("click", function(){
  34. clearCount();
  35. removeDisplay();
  36. $("#start").prop("disabled", false);
  37. });
  38. document.getElementById("pause").addEventListener("click", function(){
  39. clearCount();
  40. /*finish*/
  41. });
  42. document.getElementById("continue").addEventListener("click", function(){
  43. /*finish*/
  44. });
  45. }
  46.  
  47. function startCountdown() {
  48. displayCount(); //first function call displays number immediately instead of with delay
  49. intervalID = setInterval(function (){displayCount();}, 1000);
  50. }
  51.  
  52. function captureTime() {
  53. hours = $("#hours").val();
  54. minutes = $("#minutes").val();
  55. seconds = $("#seconds").val();
  56. }
  57.  
  58. function displayCount(){
  59. /*finish*/
  60. if (hours >= 0 && minutes >= 0 && seconds >= 0) {
  61. $("#out").html(hours + ":" + minutes + ":" + (seconds--));
  62. if(seconds == 0 && minutes > 0) {
  63. minutes--;
  64. }
  65. else if (minutes == 0 && hours > 0){
  66. hours--;
  67. }
  68. }
  69. else {
  70. clearCount();
  71. }
  72.  
  73. now = new Date();
  74. countdown = new Date(now.getFullYear, now.getMonth, now.getDate, now.getHours + hours,
  75. now.getMinutes + minutes, now.getSeconds + seconds);
  76. }
  77.  
  78. function removeDisplay() {
  79. $("#out").html("");
  80. }
  81.  
  82. function clearCount(){
  83. clearInterval(intervalID);
  84. }
  85.  
  86. function fillSeconds(){
  87. for (var i = 0; i < 60; i++) {
  88. document.getElementById("seconds").innerHTML += "<option value='" + i + "'>" + i + "</option>";
  89. document.getElementById("minutes").innerHTML += "<option value='" + i + "'>" + i + "</option>";
  90. };
  91. for (var i = 0; i < 24; i++) {
  92. document.getElementById("hours").innerHTML += "<option value='" + i + "'>" + i + "</option>";
  93. };
  94. }
  95. </script>
  96. </body>
  97. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement