当前位置:Gxlcms > JavaScript > Jquery倒计时源码分享_jquery

Jquery倒计时源码分享_jquery

时间:2021-07-01 10:21:17 帮助过:3人阅读

在静态页添加显示倒计时的容器,并引用下面脚本,代入时间参数即可使用。

timeoutDate——到期时间,时间格式为2014/01/01或2014/1/1

D——天

H——小时

M——分钟

S——秒

xs——数字0~9

效果图:

代码展示:

html:

代码如下:


jquery:

代码如下:

$().ready(function () {
CcountDown([, , timeoutDate], ['还有 DHMSxs 到期', '', ''], '#top_tuan_countdown', function () { $('#top_tuan_countdown').remove() });
})
function CcountDown(t, c, _self, fn) {
function nd(d) {
return isNaN(d) ? (d ? new Date(d).getTime() : new Date().getTime()) : d * 1000;
}
var e = [nd(t[0]), nd(t[1]), nd(t[2])], _s = _self, b;
if (t[0] && e[0] > e[1]) {
$(_s).html(c[1]);
return;
} else if (e[1] > e[2]) {
fn && fn($(_s));
$(_s).html(c[2]);
return;
}
(b = function (l) {
var l = l || (e[2] - e[1]) / 100, k = {
D: l / 36000 / 24, H: l / 36000 % 24, M: l / 600 % 60, S: l / 10 % 60, xs: l % 10
};
$(_s).html(c[0].replace(/D|H|M|S|xs/g, function (m) {
var n = parseInt(k[m]) + ''
if (n.length == 1 && m != 'D' && m != 'xs') {
n = 0 + n;
}
return n
}));
setTimeout(function () {
b(l - 1)
}, 100);
})()
}

人气教程排行