Jquery countdown source sharing

  • 2020-03-30 03:00:07
  • OfStack

Add a container to the static page that shows the countdown and refer to the following script to use the time parameter.

TimeoutDate -- due time in the format 2014/01/01 or 2014/1/1

D - day

H - hour

M - minutes

S - S

Xs - the Numbers 0 to 9

Effect:

< img border = 0 id = theimg onclick = window. The open this. (SRC) SRC = "/ / files.jb51.net/file_images/article/201405/201451690038904.jpg? 20144169053 ">

Code display:

HTML:


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

Jquery:


$().ready(function () {
    CcountDown([, , timeoutDate], [' There are  <b><font color="#ff0000" size="4">D</font>  day  </b><b><font color="#ff0000" size="4">H</font>  when  </b><b><font color="#ff0000" size="4">M</font>  points  </b><b><font color="#ff0000" size="4">S</font>  seconds  </b><b><font color="#ff0000" size="4">xs</font></b>  Due to ', '', ''], '#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);
    })()
}


Related articles: