上下班倒计时edit icon

Fork(复制)
下载
嵌入
设置
BUG反馈
index.html
style.css
index.js
现在支持上传本地图片了!
            
            <!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>上下班倒计时</title>
    <style>
        body {
            margin: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: linear-gradient(135deg, #1a73e8, #34a853);
            font-family: '微软雅黑', Arial, sans-serif;
            color: white;
        }

        .container {
            background: rgba(255, 255, 255, 0.1);
            padding: 2.5rem;
            border-radius: 15px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
            text-align: center;
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        h1 {
            font-size: 2.5rem;
            margin-bottom: 1.5rem;
            color: white;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }

        .status {
            font-size: 1.5rem;
            margin-bottom: 1rem;
            color: rgba(255, 255, 255, 0.9);
        }

        .countdown {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 1rem;
            margin-top: 1rem;
        }

        .time-box {
            background: rgba(255, 255, 255, 0.2);
            padding: 1rem;
            border-radius: 10px;
            min-width: 100px;
            text-align: center;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        .time {
            font-size: 3rem;
            font-weight: bold;
            color: white;
            margin: 0;
        }

        .label {
            font-size: 1rem;
            color: rgba(255, 255, 255, 0.8);
            margin-top: 0.5rem;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>上下班倒计时</h1>
        <div class="status" id="status"></div>
        <div class="countdown" id="countdown">
            <div class="time-box">
                <p class="time" id="hours">00</p>
                <p class="label">小时</p>
            </div>
            <div class="time-box">
                <p class="time" id="minutes">00</p>
                <p class="label">分钟</p>
            </div>
            <div class="time-box">
                <p class="time" id="seconds">00</p>
                <p class="label">秒</p>
            </div>
        </div>
    </div>

    <script>
        const workStart = '08:30';
        const workEnd = '17:30';
        const status = document.getElementById('status');
        const hours = document.getElementById('hours');
        const minutes = document.getElementById('minutes');
        const seconds = document.getElementById('seconds');

        function updateCountdown() {
            const now = new Date();
            const workDate = new Date(now);
            const offDate = new Date(now);

            // 设置工作时间和下班时间
            workDate.setHours(8, 30, 0);
            offDate.setHours(17, 30, 0);

            // 判断当前状态
            if (now >= workDate && now < offDate) {
                status.textContent = '距离下班还有';
                const timeDiff = offDate - now;
                updateDisplay(timeDiff);
            } else {
                status.textContent = '距离上班还有';
                workDate.setDate(workDate.getDate() + (workDate <= now ? 1 : 0));
                const timeDiff = workDate - now;
                updateDisplay(timeDiff);
            }
        }

        function updateDisplay(timeDiff) {
            const hoursValue = Math.floor(timeDiff / (1000 * 60 * 60));
            const minutesValue = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60));
            const secondsValue = Math.floor((timeDiff % (1000 * 60)) / 1000);

            hours.textContent = hoursValue.toString().padStart(2, '0');
            minutes.textContent = minutesValue.toString().padStart(2, '0');
            seconds.textContent = secondsValue.toString().padStart(2, '0');
        }

        // 每秒更新一次
        setInterval(updateCountdown, 1000);
        updateCountdown();
    </script>
</body>
</html>

        
预览
控制台
清空