user1377886 user1377886 - 6 months ago 39
jQuery Question

jQuery Countdown Plugin - only show non-zero periods

I'm coding a countdown with jQuery countdown plugin.

I only want it to show active ('non-zero') periods, e.g. instead of

time left: 0 Days, 0 Hours, 13 Minutes, 20 Seconds

it should only show

13 Minutes, 20 Seconds.

My code is:

expiryText: 'EXPIRED',
until: timeleft,
layout:'{d<}{dn} {dl} and {d>}{h<}{hn} {hl}, {h>}{m<}{mnn} {ml}, {m>}{s<}{snn}{sl}{s>}'

But the problem is that with this code it hides the 'Days' period, but NOT the 'Hours/Minutes'

So currently I get this:

time left: 0 Hours, 10 Minutes, 27 Seconds

What do I have to do to hide ALL zero periods?

Thank you!

Answer Source

Hiya please see here adding 2 jsfiddle to show you the difference: (Only the seconds will appear note this happens when you set **format** option of countdown as lower case) and (Zero will appear as well because I have format option set as Capital characters) update

To avoid any non-zero value to appear countdown plugin has a reference called format: with options as lower case character


[Quote]Format option == ...Use upper-case characters for mandatory periods, or the corresponding lower-case characters for optional periods, i.e. only display if non-zero. Once one optional period is shown, all the ones after that are also shown...[Unquote]


$('#highlightCountdown').countdown({until: 0, format: 'hmS',onTick: highlightLast5});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download