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

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

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);
相关推荐
TT模板3 小时前
苹果cms整合西瓜播放器XGplayer插件支持跳过片头尾
前端·html5
Wect4 小时前
React 性能优化精讲
前端·react.js·性能优化
追风筝的人er4 小时前
SpringBoot+Vue3 企业考勤如何处理法定假期?节假日方案、调休补班与工作日判断链路拆解
前端·vue.js·后端
无敌的黑星星4 小时前
Java8 CompletableFuture 实战指南
linux·前端·python
雁鸣零落5 小时前
如何在 Chrome 中查看其他浏览器的书签?书签空间订阅与侧边栏只读切换指南
前端·chrome·edge浏览器
hpoenixf5 小时前
一天上线 + 零返工:我如何给复杂前端需求建立“安全感”
前端
广州华水科技6 小时前
单北斗GNSS变形监测系统在水利工程安全保障中的应用与优势分析
前端
yqcoder6 小时前
CSS 外边距重叠(Margin Collapsing):现象、原理与完美解决方案
前端·css
山楂树の7 小时前
图像标注大坑:img图片 + Canvas 叠加标注,同步放大后标注位置偏移、对不齐?详解修复方案及亚像素处理原理
前端·css·学习·canva可画
本山德彪7 小时前
我做了一个拼豆图纸生成器,把照片秒变图纸
前端