基于Bootstrap5实现的响应式毫秒计时器秒表

所属分类: 网页特效-实用工具    2024-01-30 11:59:42

 21.1K  0  查看评论 (0)
基于Bootstrap5实现的响应式毫秒计时器秒表 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

基于Bootstrap5实现的响应式毫秒计时器秒表(共3个文件)

    • index.html

使用方法

let startTime;
        let accumulatedTime = 0;
        let running = false;

        function startStop() {
            if (running) {
                running = false;
            } else {
                startTime = null;
                requestAnimationFrame(updateTime);
                running = true;
            }
        }

        function reset() {
            accumulatedTime = 0;
            updateDisplay();
            running = false;
        }

        function updateTime(timestamp) {
            if (!startTime) {
                startTime = timestamp;
            }

            if (!running) return;

            accumulatedTime = timestamp - startTime;
            updateDisplay();

            requestAnimationFrame(updateTime);
        }

        function updateDisplay() {
            const totalMilliseconds = Math.floor(accumulatedTime);
            const days = Math.floor(totalMilliseconds / (24 * 60 * 60 * 1000));
            const hours = Math.floor((totalMilliseconds % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000));
            const minutes = Math.floor((totalMilliseconds % (60 * 60 * 1000)) / (60 * 1000));
            const seconds = Math.floor((totalMilliseconds % (60 * 1000)) / 1000);
            const milliseconds = totalMilliseconds % 1000;

            const timeString = `${formatTime(days)}:${formatTime(hours)}:${formatTime(minutes)}:${formatTime(seconds)}:${formatTime(milliseconds, 3)}`;
            document.getElementById('stopwatch').innerText = timeString;
        }

        function formatTime(value, digits = 2) {
            const paddedValue = value.toString().padStart(digits, '0');
            return paddedValue.substring(0, digits);
        }

        // Add event listener to stop the stopwatch on any touch
        $(document).on('touchstart', function () {
            running = false;
        });

        // Initial display
        updateDisplay();

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 实用工具

jquery功能丰富的网页按键事件

一款键盘操作处理插件,可根据键盘任意键或组合键,接收/响应/触发自定义操作功能。
  实用工具
 1626  0

jquery电影院在线选预订选座选票特效插件

一款在线选择座位特效插件,可自定义座位布局,支持设定购买人数,可选择连坐位置,。
  实用工具
 9775  0

jquery使用HTML的table表格创建的计算器插件

一个简单的在线计算器插件,使用JavaScript(jQuery)和HTML表构建,非常实用。
  实用工具
 7678  0

jquery自定义在线生成GUID随机字符插件

一款可自由生成随机字符的在线工具,可生成v4格式的GUID,该GUID可以用作网站或APP应用程序标识符。
  实用工具
 9831  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论