倒计时时间修正

let startTime = new Date().getTime(),
    count = 0;
// 倒计时时间修正处理
const countDownStart = () => {
    // 业务逻辑处理 ...
    count++;
    let offset = new Date().getTime() - (startTime + count * 1000),
        nextTime = 1000 - offset;
    if (nextTime < 0) nextTime = 0;
    timer = setTimeout(countDownStart, nextTime);
};
timer = setTimeout(countDownStart, 1000);

你可能感兴趣的:(倒计时时间修正)