/ Published in: JavaScript
jquery needed
Expand |
Embed | Plain Text
function countdown ( field, secs ) { var d = 0, h = 0, m = 0, s = 0; if ( secs > 0) { d = Math.floor ( secs / 86400 ); h = Math.floor ( ( secs - ( d * 86400 ) ) / 3600 ); m = Math.floor ( ( secs - ( d * 86400 ) - ( h * 3600 ) ) / 60 ); s = secs - ( d * 86400 ) - ( h * 3600 ) - ( m * 60 ); if ( h < 10 ) { h = '0' + h; } if ( m < 10 ) { m = '0' + m; } if ( s < 10 ) { s = '0' + s; } //alert ( d + "T " + h + ":" + m + ":" + s); $(document).ready(function() { var output = ""; if ( d > 0 ) { output += d + " days "; } output += h + ":" + m + ":" + s $("#" + field).html( output ); }); secs--; } else { $(document).ready(function() { $("#" + field).html( "finished" ); }); } window.setTimeout(function () { countdown ( field, secs ); }, 1000) } // countdown (id, seconds); countdown('xxx', 11111);
You need to login to post a comment.
