Posted By

vivanet on 10/30/09


Tagged

jquery countDown


Versions (?)

Countdown


 / Published in: JavaScript
 

jquery needed

  1. function countdown ( field, secs ) {
  2. var d = 0, h = 0, m = 0, s = 0;
  3. if ( secs > 0) {
  4. d = Math.floor ( secs / 86400 );
  5. h = Math.floor ( ( secs - ( d * 86400 ) ) / 3600 );
  6. m = Math.floor ( ( secs - ( d * 86400 ) - ( h * 3600 ) ) / 60 );
  7. s = secs - ( d * 86400 ) - ( h * 3600 ) - ( m * 60 );
  8. if ( h < 10 ) { h = '0' + h; }
  9. if ( m < 10 ) { m = '0' + m; }
  10. if ( s < 10 ) { s = '0' + s; }
  11. //alert ( d + "T " + h + ":" + m + ":" + s);
  12. $(document).ready(function() {
  13. var output = "";
  14. if ( d > 0 ) { output += d + " days "; }
  15. output += h + ":" + m + ":" + s
  16. $("#" + field).html( output );
  17. });
  18. secs--;
  19. }
  20. else
  21. {
  22. $(document).ready(function() {
  23. $("#" + field).html( "finished" );
  24. });
  25. }
  26. window.setTimeout(function () {
  27. countdown ( field, secs );
  28. }, 1000)
  29. }
  30.  
  31. // countdown (id, seconds);
  32. countdown('xxx', 11111);

Report this snippet  

You need to login to post a comment.