Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang = "en">
- <head>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
- </head>
- <body>
- Hours<br>
- <select id="hours"></select> <br>
- Minutes<br>
- <select id="minutes"></select> <br>
- Seconds<br>
- <select id="seconds"></select>
- <br> <br>
- <button id="start">Start!</button>
- <button id="stop">Stop!</button>
- <br> <br>
- <button id="pause">Pause!</button>
- <button id="continue">Continue!</button>
- <p id="out"></p>
- <script>
- var intervalID, seconds, minutes, hours, now, countdown;
- $(document).ready(fillSeconds);
- $(document).ready(addClickEvents);
- function addClickEvents() {
- document.getElementById("start").addEventListener("click", function(){
- captureTime();
- startCountdown();
- $("#start").prop("disabled", true);
- });
- document.getElementById("stop").addEventListener("click", function(){
- clearCount();
- removeDisplay();
- $("#start").prop("disabled", false);
- });
- document.getElementById("pause").addEventListener("click", function(){
- clearCount();
- /*finish*/
- });
- document.getElementById("continue").addEventListener("click", function(){
- /*finish*/
- });
- }
- function startCountdown() {
- displayCount(); //first function call displays number immediately instead of with delay
- intervalID = setInterval(function (){displayCount();}, 1000);
- }
- function captureTime() {
- hours = $("#hours").val();
- minutes = $("#minutes").val();
- seconds = $("#seconds").val();
- }
- function displayCount(){
- /*finish*/
- if (hours >= 0 && minutes >= 0 && seconds >= 0) {
- $("#out").html(hours + ":" + minutes + ":" + (seconds--));
- if(seconds == 0 && minutes > 0) {
- minutes--;
- }
- else if (minutes == 0 && hours > 0){
- hours--;
- }
- }
- else {
- clearCount();
- }
- now = new Date();
- countdown = new Date(now.getFullYear, now.getMonth, now.getDate, now.getHours + hours,
- now.getMinutes + minutes, now.getSeconds + seconds);
- }
- function removeDisplay() {
- $("#out").html("");
- }
- function clearCount(){
- clearInterval(intervalID);
- }
- function fillSeconds(){
- for (var i = 0; i < 60; i++) {
- document.getElementById("seconds").innerHTML += "<option value='" + i + "'>" + i + "</option>";
- document.getElementById("minutes").innerHTML += "<option value='" + i + "'>" + i + "</option>";
- };
- for (var i = 0; i < 24; i++) {
- document.getElementById("hours").innerHTML += "<option value='" + i + "'>" + i + "</option>";
- };
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement