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

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

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);
相关推荐
leoZ23112 小时前
记忆系统与 Agent 定制完全指南(三):记忆的检索与使用
前端·chrome
遇乐的果园12 小时前
前端学习笔记-vue状态管理优化
前端·笔记·学习
GIS阵地14 小时前
QgsSingleBandPseudoColorRenderer 完整详解(QGIS 3.40.13 C++)
开发语言·前端·c++·qt·qgis
刘较瘦_14 小时前
AI 开发中的 Git Submodule 父子仓库模式:前后端分仓管理与协作实践
前端·github
牧艺14 小时前
cos-design WeatherBackground:用 Canvas 做一个「会变天」的背景引擎
前端·canvas·视觉设计
OpenTiny社区14 小时前
深度解析 LSP 如何为 AI 装上“眼睛”
前端·ai编程
布列瑟农的星空14 小时前
流程类SVG画布的通用开发范式
前端
fsssb14 小时前
Chromium 源码学习笔记(七):那些跨进程的调用,底下都是同一个东西——Mojo
前端
gis开发之家15 小时前
《Vue3 从入门到大神35篇》Vue3 源码详解(五):effect 依赖收集原理——track 与 trigger 是如何工作的?
javascript·typescript·前端框架·vue3·vue3源码
MichaelJohn15 小时前
从零星白屏到“启发式缓存”,记录一次刚接手屎山的惊险排查
前端