网页秒表小工具

网页秒表小工具

效果展示

在这里插入图片描述

HTML代码

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>简洁秒表</title>
    <style>
		
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f4f4f4;
        }
        .timer-container {
            text-align: center;
        }
        .display {
            font-size: 48px;
            margin-bottom: 20px;
        }
        .button {
            padding: 10px 20px;
            margin: 5px;
            font-size: 16px;
            cursor: pointer;
        }
        #start, #pause {
            background-color: #4CAF50;
            color: white;
        }
        #reset {
            background-color: #f44336;
            color: white;
        }
    </style>
</head>
<body>
    <div class="timer-container">
        <div class="display" id="timerDisplay">00:00:00</div>
        <button class="button" id="start">开始</button>
        <button class="button" id="pause">暂停</button>
        <button class="button" id="reset">重置</button>
    </div>

    <script>
        let seconds = 0;
        let interval = null;

        function updateTimerDisplay() {
            let hours = Math.floor(seconds / 3600);
            let minutes = Math.floor((seconds - (hours * 3600)) / 60);
            let secs = seconds % 60;

            hours = hours < 10 ? '0' + hours : hours;
            minutes = minutes < 10 ? '0' + minutes : minutes;
            secs = secs < 10 ? '0' + secs : secs;

            document.getElementById('timerDisplay').textContent = 
                hours + ':' + minutes + ':' + secs;
        }

        document.getElementById('start').addEventListener('click', function() {
            if (interval) clearInterval(interval);
            interval = setInterval(function() {
                seconds++;
                updateTimerDisplay();
            }, 1000);
        });

        document.getElementById('pause').addEventListener('click', function() {
            clearInterval(interval);
        });

        document.getElementById('reset').addEventListener('click', function() {
            clearInterval(interval);
            seconds = 0;
            updateTimerDisplay();
        });
    </script>
</body>
</html>
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值