大佬们指点一下倒计时有什么问题吗?

看了另外一张帖子,关于倒计时组件的,就自己写了一个,大家帮忙看下,写得怎么样?有什么问题,可以指出来!

html 复制代码
<div class="time"></div>
js 复制代码
function countdown(time) {
    let lastTime = Date.now();
    let rafId;
    function refresh() {
        const curTime = Date.now();
        const more = curTime - lastTime - 1000;
        if (more > 0) {
            lastTime = curTime + more;
            const nextTime = time--;
            if (nextTime === 0) {
                cancelAnimationFrame(rafId);
                return;
            }
            update(time);
        }
        rafId = requestAnimationFrame(refresh);
    }

    function update(restTime) {
        const h = restTime > 3600 ? Math.floor(restTime / 60) : 0;
        const m = Math.floor((restTime - h * 3600) / 60);
        const s = restTime - h * 3600 - m * 60;
        const dom = document.querySelector('.time');
        dom.innerHTML = `剩余${h}小时${m}分钟${s}秒`;
    }
    refresh();
    update(time);
}
countdown(1000);
相关推荐
q***57743 小时前
WebSpoon9.0(KETTLE的WEB版本)编译 + tomcatdocker部署 + 远程调试教程
前端
Q***l6873 小时前
Vue增强现实案例
前端·vue.js·ar
十里-4 小时前
前端监控1-数据上报
前端·安全
初学者,亦行者4 小时前
DevUI微前端集成实战解析
前端·typescript
han_4 小时前
前端高频面试题之CSS篇(一)
前端·css·面试
b***74884 小时前
Vue开源
前端·javascript·vue.js
不知更鸟4 小时前
前端报错:快速解决Django接口404问题
前端·python·django
D***t1314 小时前
React图像处理案例
前端
万少5 小时前
我是如何使用 Trae IDE 完成《流碧卡片》项目的完整记录
前端·后端·ai编程
9***Y485 小时前
前端微服务
前端·微服务·架构