4 replies
I am creating countdown timer for 70 seconds before the download link is appear
I want it appear like 1:10 rather than 70 seconds, how to do that ?

preview :
Countdown Timer

this is the script I am using :

<script type="text/javascript">
jQuery(document).ready(function() {
var sec = 70
var timer = setInterval(function() {
$("#mdtimer span").text(sec--);
if (sec == 0) {
$("#makingdifferenttimer").delay(1000).fadeIn(1000 );
$("#mdtimer").hide(1000) .fadeOut(fast);}
},1000);
});
</script>

<center>
<a class="button" href="http://www.downloadlink.com/" id="makingdifferenttimer" rel="nofollow" style="display: none;" target="_blank">Download</a>
</center>

<div id="mdtimer">
<div style="font-size: large; text-align: center;">
<b>Please Wait <span>70</span> seconds</b></div>
</div>
#countdown #timer
  • Profile picture of the author BinaryKing
    This should help you! Just add the lines for minutes and then display it properly with first minutes, then : and then the seconds

    Javascript seconds to minutes and seconds - Stack Overflow
    {{ DiscussionBoard.errors[9017743].message }}
  • Profile picture of the author zeurois
    This should do the job (I haven't tested it though):

    var deadline = 70;

    function formatTime(time) {
    var minutes = parseInt(time / 60);
    var seconds = parseInt(time % 60);
    return (minutes < 10 ) ? '0' + minutes : minutes + ':' + (seconds < 10) ? '0' + seconds : seconds;
    }

    function runTimer() {
    deadline--;

    $("#mdtimer span").html(formatTime(deadline));

    if (sec <= 0) {
    $("#makingdifferenttimer").delay(1000).fadeIn(10 00 );
    $("#mdtimer").hide(1000) .fadeOut(fast);

    return;
    }

    setTimeout(function(){ runTimer(); }, 1000);
    }
    {{ DiscussionBoard.errors[9069120].message }}
    • Profile picture of the author tweakr
      Here's what you're looking for:

      Code:
      jQuery(document).ready(function() {
              var sec = 70;
       
              function formatTime(s) {
                  var m = Math.floor(s/60); //Get remaining minutes
                  s -= m*60;
                  return (m < 10 ? m : m)+":"+(s < 10 ? '0'+s : s); //zero padding on minutes and seconds
              }
       
              var timer = setInterval(function() {
                      var count = sec--;
                      $("#mdtimer span").text(formatTime(count));
                      if (sec == 0) {
                              $("#makingdifferenttimer").delay(1000).fadeIn(1000);
                              $("#mdtimer").hide(1000) .fadeOut(fast);
                      }
              }, 1000);
       
      });
      I created a pastebin with everything in it.
      {{ DiscussionBoard.errors[9069238].message }}
  • Profile picture of the author marioxiao
    It's working. thanks a million. you're great
    {{ DiscussionBoard.errors[9071645].message }}

Trending Topics