我目前正在研究CountDown。但是,我试图在到达日期后显示其他显示。任何建议都将受到高度赞赏。一旦间隔小于0,就无法ping if语句中不起作用的内容。
const second = 1000,
minute = second * 60,
hour = minute * 60,
day = hour * 24;
let countDown = new Date('Sep 06, 2018 23:00:00').getTime(),
x = setInterval(function() {
let now = new Date().getTime(),
distance = countDown - now;
document.getElementById('days').innerText = Math.floor(distance / (day)),
document.getElementById('hours').innerText = Math.floor((distance % (day)) / (hour)),
document.getElementById('minutes').innerText = Math.floor((distance % (hour)) / (minute)),
document.getElementById('seconds').innerText = Math.floor((distance % (minute)) / second);
//do something later when date is reached
if (distance < 0) {
clearInterval(x);
'its time!';
}
//if (distance < 0) {
// clearInterval(x);
// document.getElementById('head').innerText= 'its Time';
//}
}, second)
html:
<div class="container">
<h1 id="head">My birthday Coming Soon:</h1>
<ul>
<li><span id="days"></span>days</li>
<li><span id="hours"></span>Hours</li>
<li><span id="minutes"></span>Minutes</li>
<li><span id="seconds"></span>Seconds</li>
</ul>
</div>