简体   繁体   English

Countdown.js如何显示0个单位

[英]Countdownjs how to show 0 units

I am using the JS library CountdownJS. 我正在使用JS库CountdownJS。 I am wanting to return a zero value for each of the time units when applicable. 我想在适用时为每个时间单位返回零值。 Currently when the value is 0 the unit just doesn't show. 当前,当值为0时,仅不显示单位。

Here's what I want to see: 这是我想看到的:

在此处输入图片说明

Here's what I currently see: 这是我目前看到的:

在此处输入图片说明

Anyone familiar with the library know where in the source I would look to update this? 任何熟悉该库的人都知道我将在源代码的哪儿进行更新?

Ref: http://countdownjs.org/readme.html 参考: http : //countdownjs.org/readme.html

Here's a really simple countdown function I wrote a while back. 这是我前一段时间写的一个非常简单的倒计时功能。 Feel free to use it however. 随意使用它。

 var t = new Date(2014,11,25,9,30), p = document.getElementById("time"), timer; var u = function () { var delta = t - new Date(), d = delta / (24 * 3600 * 1000) | 0, h = (delta %= 24 * 3600 * 1000) / (3600 * 1000) | 0, m = (delta %= 3600 * 1000) / (60 * 1000) | 0, s = (delta %= 60 * 1000) / 1000 | 0; if (delta < 0) { clearInterval(timer); p.innerHTML = "timer's finished!"; } else { p.innerHTML = d + "d " + h + "h " + m + "m " + s + "s"; } } timer = setInterval(u, 1000); 
 <h1 id="time"></h1> 

The only tricky part might be my use of 唯一棘手的部分可能是我对

h = (delta %= 24 * 3600 * 1000) / (3600 * 1000) | 0

delta %= ... returns delta , after performing the %= . delta %= ...执行%=后返回delta This was just to save characters. 这只是为了保存字符。 If you don't like this, you can just separate the delta %= ... part: 如果您不喜欢,则可以将delta %= ...部分分开:

delta %= 24 * 3600 * 1000;
h = delta / (3600 * 1000) | 0;
// ... do the same for the rest

fiddle 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM