比赛倒计时软件(界面非常漂亮)基于html开发的源代码真心值得拥有

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>倒计时计时器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .header {
            background-color: #88001b;
            color: white;
            height: 180px;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 100px;
        }

        .timer {
            display: flex;
            justify-content: center;
            align-items: center;
            height: calc(100vh - 280px);
            font-size: 30vw;
        }

        .buttons {
            position: fixed;
            bottom: 0;
            width: 100%;
            display: flex;
            justify-content: space-around;
            padding: 10px 0;
        }

        button {
            font-size: 20px;
            padding: 10px 20px;
        }
    </style>
</head>

<body>
    <div class="header">比赛倒计时</div>
    <div class="timer" id="timer">01:00</div>
    <div class="buttons">
        <button id="startTimer">开始计时</button>
        <button id="pauseTimer">暂停计时</button>
        <button id="fullscreenToggle">全屏显示</button>
        <button id="clearData">清空数据</button>
        <button id="customTime">自定义时间</button>
    </div>

    <audio id="startSound" src="start-timer-sound.mp3"></audio>
    <audio id="warningSound" src="warning-timer-sound.mp3"></audio>

    <script>
        let totalSeconds = 60;
        let countdown;
        let warningPlayed = false;
        let isPaused = false;

        function startTimer() {
            document.getElementById('startSound').play();
            if (!countdown && !isPaused) {
                countdown = setInterval(timerFunction, 1000);
            } else if (isPaused) {
                countdown = setInterval(timerFunction, 1000);
                isPaused = false;
            }
        }

        function pauseTimer() {
            clearInterval(countdown);
            countdown = null;
            isPaused = true;
        }

        function timerFunction() {
            if (!isPaused) {
                totalSeconds--;
                const minutes = Math.floor(totalSeconds / 60);
                const seconds = totalSeconds % 60;
                document.getElementById('timer').textContent = `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;

                if (totalSeconds === 10 && !warningPlayed) {
                    document.getElementById('warningSound').play();
                    warningPlayed = true;
                }

                if (totalSeconds <= 0) {
                    clearInterval(countdown);
                    document.getElementById('timer').textContent = "时间到";
                }
            }
        }

        // 按空格键开始或暂停计时
        document.addEventListener('keydown', function (event) {
            if (event.code === 'Space') {
                event.preventDefault();
                if (!countdown || isPaused) {
                    startTimer();
                } else {
                    pauseTimer();
                }
            }
        });

        // 按回车键清空数据
        document.getElementById('clearData').addEventListener('click', function () {
            totalSeconds = 60;
            clearInterval(countdown);
            countdown = null;
            isPaused = false;
            document.getElementById('timer').textContent = "01:00";
        });

        // 弹出自定义时间对话框
        document.getElementById('customTime').addEventListener('click', function () {
            const inputTime = prompt('请输入倒计时时间(单位:秒)');
            const time = parseInt(inputTime);
            if (isNaN(time)) {
                alert('输入的时间无效,请输入一个有效的数字');
            } else {
                totalSeconds = time;
                document.getElementById('timer').textContent = `${String(Math.floor(time / 60)).padStart(2, '0')}:${String(time % 60).padStart(2, '0')}`;
                if (document.fullscreenElement) {
                    document.exitFullscreen();
                }
            }
        });

        document.getElementById('startTimer').addEventListener('click', startTimer);
        document.getElementById('pauseTimer').addEventListener('click', pauseTimer);

        document.getElementById('fullscreenToggle').addEventListener('click', function () {
            if (!document.fullscreenElement) {
                document.documentElement.requestFullscreen().then(() => {
                    this.textContent = '退出全屏模式';
                }).catch(err => {
                    alert(`无法进入全屏模式: ${err.message}`);
                });
            } else {
                if (document.exitFullscreen) {
                    document.exitFullscreen().then(() => {
                        this.textContent = '全屏显示';
                    }).catch(err => {
                        alert(`无法退出全屏模式: ${err.message}`);
                    });
                }
            }
        });
    </script>
</body>

</html>

  • 6
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,这是一个简单的倒计时烟花绽放的HTMLCSS源代码,你可以根据自己的需求进行修改: HTML代码: ``` <div class="countdown"> <div class="countdown-number"> <span class="days"></span> <span class="hours"></span> <span class="minutes"></span> <span class="seconds"></span> </div> <div class="countdown-label"> <span class="days-label">Days</span> <span class="hours-label">Hours</span> <span class="minutes-label">Minutes</span> <span class="seconds-label">Seconds</span> </div> </div> <div class="fireworks"> <div class="before"></div> <div class="after"></div> </div> ``` CSS代码: ``` body { background-color: #000; } .countdown { display: flex; justify-content: center; align-items: center; font-family: Arial, sans-serif; font-size: 2rem; color: #fff; } .countdown-number { display: flex; } .countdown-number > span { padding: 0.5rem; border-radius: 0.25rem; background-color: #333; margin-right: 0.5rem; } .countdown-label { display: flex; flex-direction: column; } .countdown-label > span { font-size: 0.75rem; } .fireworks { position: relative; width: 100%; height: 100%; } .before, .after { position: absolute; top: -50%; left: -50%; right: -50%; bottom: -50%; margin: auto; width: 100%; height: 100%; background-image: radial-gradient(circle, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); background-size: 400% 400%; animation: fireworks 5s ease-in-out infinite; } .after { animation-delay: 2.5s; } @keyframes fireworks { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大飞哥软件自习室

希望支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值