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

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

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);
相关推荐
nece00126 分钟前
vue3杂记
前端·vue
Coder_Boy_29 分钟前
基于SpringAI的在线考试系统设计总案-知识点管理模块详细设计
android·java·javascript
Carry3451 小时前
不清楚的 .gitignore
前端·git
张鑫旭1 小时前
AI时代2025年下半年学的这些Web前端特性有没有用?
前端·ai编程
pinkQQx1 小时前
H5唤醒APP技术方案入门级介绍
前端
Lefan1 小时前
UniApp 隐私合规神器!一键搞定应用市场审核难题 - lf-auth 隐私合规助手
前端
Null1551 小时前
浏览器唤起桌面端应用(进阶篇)
前端·浏览器
Jing_Rainbow1 小时前
【Vue-2/Lesson62(2025-12-10)】模块化与 Node.js HTTP 服务器开发详解🧩
前端·vue.js·node.js
风度前端2 小时前
用了都说好的 uniapp 路由框架
前端
冴羽2 小时前
2026 年 Web 前端开发的 8 个趋势!
前端·javascript·vue.js