Results 1 to 3 of 3

Thread: Universal Countdown : 2-digit minimum?

  1. #1
    Join Date
    Apr 2007
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Universal Countdown : 2-digit minimum?

    1) Script Title:
    Universal Countdown

    2) Script URL (on DD):
    http://www.dynamicdrive.com/dynamici...lcountdown.htm

    3) Describe problem:

    Would it be possible to ensure that the Hours, Minutes and Seconds (only) fields always be 2 digits? In other words, "01" instead of "1". This is not important for the days, because the days can be 1, 2 or 3 digits... but since the hours, minutes and seconds can never be more than 2 digits -- and most often ARE 2 digits -- it would be helpful for those 3 specific fields.

    The reason is that when 10 seconds becomes 9 seconds, everything moves. When 10 minutes becomes 9 minutes, same thing.

    Just having 10 become 09 instead of 9 would make everything look a lot better, and behave more professionally (I find).

    BONUS: If we can change the color of the "0" that gets added to the single digit, that would be even better (we could make it slightly darker, for a nice effect).

    But just having 01, 02, 03 instead of 1, 2, 3 would be a great help.

    thanks!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,004
    Thanks
    44
    Thanked 3,199 Times in 3,161 Posts
    Blog Entries
    12

    Default

    This would best be done in the format results function used. For example, in the one for the LCD display:

    Code:
    //2) Display countdown with a stylish LCD look, and display an alert on target date/time
    function formatresults2(){
    if (this.timesup==false){ //if target date/time not yet met
    function pad(n){
    	return n - 0 < 10? '<span class="darker">0<\/span>' + n : n;
    }
    var displaystring="<span class='lcdstyle'>"+arguments[0]+" <sup>days</sup> "+pad(arguments[1])+" <sup>hours</sup> "+pad(arguments[2])+" <sup>minutes</sup> "+pad(arguments[3])+" <sup>seconds</sup></span> left until launch time"
    }
    else{ //else if target date/time met
    var displaystring="" //Don't display any text
    alert("Launch time!") //Instead, perform a custom alert
    }
    return displaystring
    }
    Now (to make the added zero actually darker) you could put in your style section a rule something like so:

    Code:
    .darker {
    	color: #0b0;
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Apr 2007
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Awesome! :-)

    (Another satisfied customer!)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •