联系我们
简单又实用的WordPress网站制作教学
当前位置:网站首页 > 网页前端技术 > 正文

Jquery倒计时源码分享 - Web前端

作者:98wpeu发布时间:2026-07-05分类:网页前端技术浏览:3


导读:在静态页添加显示倒计时的容器,并引用下面脚本,代入时间参数即可使用。timeoutdate——到期时间,时间格式为2014/01/01或2014/1/1D——天H——小时M——分钟...

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

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

D——天

H——小时

M——分钟

S——秒

xs——数字0~9

效果图:

代码展示:

html:

复制代码 代码如下:
<span id="top_tuan_countdown"></span>

JQuery:

复制代码 代码如下:
$().ready(function () {
    CcountDown([, , timeoutDate], ['还有 <b><fontcolor="#ff0000" size="4">D</font> 天 </b><b><font color="#ff0000" size="4">H</font> 时 </b><b><font color="#ff0000" size="4">M</font> 分 </b><b><font color="#ff0000" size="4">S</font> 秒 </b><b><font color="#ff0000" size="4">xs</font></b> 到期', '', ''], '#top_tuan_countdown', function () { $('#top_tuan_countdown').remove() });
})
function CcountDown(t, c, _self, fn) {
    function nd(d) {
        returnisNaN(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);
    })()
}

标签:倒计时源码WebJquery


网页前端技术排行
最近发表
网站分类
标签列表