计时器

2018-11-05  本文已影响0人  令武

// 15分钟计时

var timers = null;

var initMax = parseInt(900);//

var intDiff = parseInt(0);// 订单时间

// 15分钟计时

// 1分钟倒计时

var fiveTimer = null;

var fiveInit = parseInt(60);// 倒计时总秒数量

// 1分钟倒计时

// 上麦计时

var marketTime = null;// 麦上时间

var marketInit = parseInt(0);// 麦上时间初始化

// 上麦计时

// 缓存有时间读缓存

if ('intDiff' in cacheOrder) {

    intDiff = cacheOrder.intDiff;

    console.log('15分钟', intDiff)

}

// 15分钟计时

function chronoscope(intDiff) {

    timers = window.setInterval(function () {

        var day = 0,

            hour = 0,

            minute = 0,

            second = 0;// 时间默认值       

        if (intDiff < initMax) {

            minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);

            second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);

            intDiff++;

            cacheOrder.intDiff = intDiff; // 赋值时间

            sessionStorage.setItem('order', JSON.stringify(cacheOrder));// 储存时间

        } else {

            clearInterval(timers); // 清除定时器

            orderClose(4); // 弃单

        }

        // console.log(intDiff,'15分钟');

        if (minute <= 9) minute = '0' + minute;

        if (second <= 9) second = '0' + second;

        $('.minute_show').html('<s></s>' + minute + '分');

        $('.second_show').html('<s></s>' + second + '秒');

    }, 1000);

}

// 麦上时间计时器

function market(timeBox) {

    this.timeBox = timeBox;

    market.prototype.marketSet = function () {

        marketTime = window.setInterval(function () {

            let hour = 0,

                minute = 0,

                second = 0;// 时间默认值

            day = Math.floor(marketInit / (60 * 60 * 24));

            hour = Math.floor(marketInit / (60 * 60)) - (day * 24);

            minute = Math.floor(marketInit / 60) - (day * 24 * 60) - (hour * 60);

            second = Math.floor(marketInit) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);

            marketInit++;

            cacheOrder.marketInit = marketInit; // 赋值时间

            sessionStorage.setItem('order', JSON.stringify(cacheOrder));// 储存时间           

            if (hour <= 9) hour = '0' + hour;

            if (minute <= 9) minute = '0' + minute;

            if (second <= 9) second = '0' + second;

            $(timeBox).html(`开启时长:${hour} 小时 ${minute} 分钟`);

        }, 1000)

    }

}

var wheat = new market('.voice-time');

// 麦上时间计时器

// 1分钟倒计时

function countdown(fiveInit) {

    fiveTimer = window.setInterval(function () {

        console.log(fiveInit, '***************************************')

        if (fiveInit > 0) {

            $(".ts-order").addClass('un-click');

            $(".ts-order").attr('disabled', true);

            $('#five-times').html('推送更多大神(' + fiveInit + 's)');

            fiveInit--;

            cacheOrder.fiveInit = fiveInit; // 赋值时间

            sessionStorage.setItem('order', JSON.stringify(cacheOrder));// 储存时间

            console.log(fiveInit);

        } else {

            console.log('禁用大神按钮')

            clearInterval(fiveTimer);

            $(".ts-order").removeClass('un-click');

            $(".ts-order").attr('disabled', false);

            $('#five-times').html('推送更多大神');

        }

    }, 1000);

}

谢谢各位~END

上一篇下一篇

猜你喜欢

热点阅读