jq倒计时html源码,Jquery倒计时源码分享

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

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

D——天

H——小时

M——分钟

S——秒

xs——数字0~9

效果图:

6db58346614acd2cccda890c15ae6e01.png

代码展示:

html:

jquery:

$().ready(function () {

CcountDown([, , timeoutDate], ['还有 D 天 H 时 M 分 S 秒 xs 到期', '', ''], '#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);

})()

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值