实例
<span id="day_show">0天</span>
<strong id="hour_show">0时</strong>
<strong id="minute_show">0分</strong>
<strong id="second_show">0秒</strong>
timer(50);
function timer(intDiff) {
window.setInterval(function() {
var day = 0,
hour = 0,
minute = 0,
second = 0; //时间默认值
if (intDiff > 0) {
day = Math.floor(intDiff / (60 * 60 * 24));
hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
}
if (minute <= 9) minute = '0' + minute;
if (second <= 9) second = '0' + second;
$('#day_show').html(day + "天");
$('#hour_show').html('<s id="h"></s>' + hour + '时');
$('#minute_show').html('<s></s>' + minute + '分');
$('#second_show').html('<s></s>' + second + '秒');
用于毫秒倒计时
//countdaojishi1('haomiao_show', 99,10);
intDiff--;
}, 1000);
}
function countdaojishi1(obj, startv, endv) {
var options = {
useEasing: true,
useGrouping: false,
separator: ',',
decimal: '.',
};
var demo = new CountUp(obj, startv, endv, 0, 2.5, options);
if (!demo.error) {
demo.start();
} else {
console.error(demo.error);
}
}
运行实例 »
点击 "运行实例" 按钮查看在线实例
转自:http://newmiracle.cn/?m=201712
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!