倒计时时间修正

2019-08-01  本文已影响0人  loewe0202
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);
上一篇下一篇

猜你喜欢

热点阅读