活动倒计时脚本

  • 下面的源码是这个当天 9:30 ~ 10:30 的活动展示的倒计时读秒
var nowDate = $('#now_date1').val();//服务器当前时间

//活动倒计时
    this.countdown = function () {
        var djsdom = $('#countdown');
        if (djsdom.length > 0) {
            var start = new Date(nowDate);
            start.setHours(9, 30, 00);
            var end = new Date(nowDate);
            end.setHours(10, 30, 00);
            var f;
            var now = new Date(nowDate);
            f = setInterval(function () {
                if (now >= start && now <= end) {
                    now.setTime(now.getTime() + 1000);      //循环加1秒
                    var _times = end - now;
                    var _min = (parseInt(_times / 1000 / 60 % 60)).toString();
                    var _s = (parseInt(_times / 1000 % 60)).toString();
                    if (_min.length == 1) {
                        _min = '0' + _min;
                    }
                    if (_s.length == 1) {
                        _s = '0' + _s;
                    }
                    //console.log(_min + '\n' + _s);
                    djsdom.html('
' + _min.substring(0, 1) + '' + _min.substring(1) + '' + _s.substring(0, 1) + '' + _s.substring(1) + '
'); } else { clearInterval(f); djsdom.html(''); } }, 1000); }; };

效果图


活动倒计时脚本_第1张图片
GIF3.gif

你可能感兴趣的:(活动倒计时脚本)