https://github.com/HugoGiraudel/Countdown.js
代码来源微擎应用市场
html代码:
<div class="count-down" data-countdown="2019-02-15 00:00:00"> <span class="num day">00</span> <span class="unit">天</span> <span class="num hour">00</span> <span class="unit">时</span> <span class="num minute">00</span> <span class="unit">分</span> <span class="num second">00</span> <span class="unit">秒</span> </div>
js代码:
$('[data-countdown]').each(function(index) { var $this = $(this); var finalDate = $this.data('countdown') || new Date(); finalDate = finalDate.replace(/-/g,"/"); $this.attr('id', 'countdown-' + index) new Countdown({ // Custom selector: '#countdown-' + index, dateEnd: new Date(finalDate), leadingZeros: true, // <b> {days} </b> days, {hours} hours, {minutes} minutes !' msgPattern : '<span class="num day">{days}</span>' + '<span class="unit">天</span>' + '<span class="num hour">{hours}</span>' + '<span class="unit">时</span>' + '<span class="num minute"> {minutes} </span>' + '<span class="unit">分</span>' + '<span class="num second">{seconds}</span>' + '<span class="unit">秒</span>', msgAfter: '活动结束', onStart: function() { }, onEnd: function() { } }); })