Monday 27 February 2017

Lightweight countdown timer

School days are pretty awesome, run back kicking and hailing all the these we could do, Physics and Chemistry class were taught for me but i made it all through, stop watch and countdown were used those time to determined how long reaction can take place, so far so good.
Surely get through that using javascript believe me working around js is really fun and great, every programming language has it's weak point somewhere, am going to cut it pieces providing solution, having good time with js, I bet you won't forget this day you make up your mind to try javascript, speeding that one minute is a worthwhile. if you're working on a timing project this will give you a workout. pretty sure about that. we're just going to great function in js and parse it around to get what you desire, easy right?

Download ScriptDemo

<script>
     $(document).ready(function(){

   var c = 60*60*60;
         var t;
            timedCount();
            function timedCount() {
             var hours = parseInt( c / 3600 ) % 24;
             var minutes = parseInt( c / 60 ) % 60;
             var seconds = c % 60;
             var result = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds  < 10 ? "0" + seconds : seconds);
             $('#timer').html(result);
                if(c == 0 ){ c = 60*60*60; }
                c = c - 1;
                t = setTimeout(function(){ timedCount() }, 1000);
            }
     });
    </script>

c = 60*60*60; the very first 60secs count for hours and second 60 sec count for minuuteand third count for secs
parse it against 24 hours, parse minut against 60 seconds. this is the workthough.

Call up $('#timer').html(result); to populate the counting figure, a function was created timedCount()

Here is the demo just in case, u wanna work it around to suit your need or download the code below.



Previous Post
Next Post

post written by:

0 Comments:

Hit me with a comment!