jquery倒计时代码

jquery倒计时代码

    <span id="day_show">0天</span>
                <strong id="hour_show">0时</strong>
                <strong id="minute_show">0分</strong>
                <strong id="second_show">0秒</strong>

    timer(50);

    function timer(intDiff) {
        window.setInterval(function() {
            var day = 0,
                hour = 0,
                minute = 0,
                second = 0; //时间默认值
            if (intDiff > 0) {
                day = Math.floor(intDiff / (60 * 60 * 24));
                hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
                minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
                second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
            }
            if (minute <= 9) minute = '0' + minute;
            if (second <= 9) second = '0' + second;
            $('#day_show').html(day + "天");
            $('#hour_show').html('<s id="h"></s>' + hour + '时');
            $('#minute_show').html('<s></s>' + minute + '分');
            $('#second_show').html('<s></s>' + second + '秒');
//用于毫秒倒计时
               //countdaojishi1('haomiao_show', 99,10);
            intDiff--;
        }, 1000);
    }


注意haomiao_show是id元素





function countdaojishi1(obj, startv, endv) {
    var options = {  
        useEasing: true,
          useGrouping: false,
          separator: ',',
          decimal: '.',
    };
    var demo = new CountUp(obj, startv, endv, 0, 2.5, options);
    if (!demo.error) {  
        demo.start();
    } else {  
        console.error(demo.error);
    }
}


原创文章如转载,请注明本文链接: http://newmiracle.cn/?p=2272

发表评论

电子邮件地址不会被公开。 必填项已用*标注