tick.js 1.51 KB
/**
 * [秒抢页面js]
 * author: 陈峰<feng.chen@yoho.cn>
 * date: 2016/09/08
 */
var $ = require('yoho-jquery'),
    IScroll = require('yoho-iscroll'),
    tip = require('../plugin/tip'),
    seckillObj = {};
require('../common');
var offsetTime = $('.seckill-count').find('.secKill-date').val();
seckillObj = {
    el: {
        // doms
        $navUl: $('.nav-ul'),
        $navList: $('.nav-list'),

        // 变量
        times: $('.nav-ul>li').length,
        startX: 0,
        timeWidth: 0,
        focusTimeWidth: 0,
        iScroll: null,
        currentTick: null
    },


    startTick: function(elem, offsetTime) {
        var that = this,
            $el = this.el,
            hour = parseInt(offsetTime / (60 * 60), 10),
            minute = parseInt(offsetTime % (60 * 60) / 60, 10),
            second = offsetTime % 60;

        if (offsetTime) {
            $(elem).find('.tick.hour').text(hour < 0 ? '00' : (hour < 10 ? ('0' + hour) : hour));
            $(elem).find('.tick.minute').text(minute < 0 ? '00' : (minute < 10 ? ('0' + minute) : minute));
            $(elem).find('.tick.second').text(second < 0 ? '00' : (second < 10 ? ('0' + second) : second));
            if (offsetTime <= 0) { // 结束倒计时刷新状态
                that.refreshList(elem);
            } else {
                $el.currentTick = setTimeout(function() {
                    that.startTick(elem, --offsetTime);
                }, 1000);
            }
        }

    }
};

seckillObj.startTick($('.seckill-count-num'), offsetTime);