JS 倒计时

/**
 * 倒计时
 * @param el 倒计时的父级元素
 * @param intDiff  倒计时总秒数量
 * 时间默认值 day,hours,minutes,second
 */

var count_down = function (el,intDiff){

    var day = 0,
        hours = 0,
        minutes = 0,
        seconds = 0;

    var timer = setInterval(function(){

        if(intDiff > 0)
        {
            day = Math.floor(intDiff / (60 * 60 * 24));
            hours = Math.floor(intDiff / (60 * 60)) - (day * 24);
            minutes = Math.floor(intDiff / 60) - (day * 24 * 60) - (hours * 60);
            seconds = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hours * 60 * 60) - (minutes * 60);

        }
        else
        {
            //取消定时器
            clearInterval(timer);

        }

        if (day < 10) day = '0' + day;
        if (hours < 10) hours = '0' + hours;
        if (minutes < 10) minutes = '0' + minutes;
        if (seconds < 10) seconds = '0' + seconds;

        $(el+' .day').html(day);
        $(el+' .hours').html(hours);
        $(el+' .minutes').html(minutes);
        $(el+' .seconds').html(seconds);

        intDiff--;

    }, 1000);
};
上一篇:蚂蚁金服分布式链路跟踪组件 SOFATracer 总览|剖析


下一篇:MySQL添加用户并赋予权限