[收藏]乐蜂网SALES倒计时源码展示

这是一个基于jquey写的倒计时。当然代码有点小改动,只是改了一下展示效果。

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

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

D——天

H——小时

M——分钟

S——秒

xs——数字0~9

效果图:

代码展示:

html:

 

<span id="top_tuan_countdown"></span>

 

jquery:

复制代码
$().ready(function () {
var timeoutDate = '2014/06/12';//必须要‘/’.也可以传递自己想要的时间过来. CcountDown([, , timeoutDate], [
'还有&nbsp;<b><font color="#ff0000" size="4">D</font>&nbsp;天&nbsp;</b><b><font color="#ff0000" size="4">H</font>&nbsp;时&nbsp;</b><b><font color="#ff0000" size="4">M</font>&nbsp;分&nbsp;</b><b><font color="#ff0000" size="4">S</font>&nbsp;秒&nbsp;</b><b><font color="#ff0000" size="4">xs</font></b>&nbsp;到期', '', ''], '#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); })() }
posted @ 2014-04-16 17:08  大江孤水  阅读(114)  评论(0编辑  收藏  举报