DATAWHALE AI冬令营番茄钟

要求:请你基于html、tailwind css和javascript,帮我设计一个“番茄时钟”。要求UI简洁美观大方,同时具有呼吸感,点击开始计时、点击暂停计时和重置计时的功能能够完美实现

AI代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>番茄时钟</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f5f5f5;
        }
        .timer {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
        }
        .timer h1 {
            font-size: 4rem;
            margin-bottom: 2rem;
        }
        .timer button {
            font-size: 2rem;
            padding: 1rem 2rem;
            margin: 1rem;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        .timer button:hover {
            background-color: #ddd;
        }
    </style>
</head>
<body>
    <div class="timer">
        <h1 id="timer-display">25:00</h1>
        <button id="start-btn">开始</button>
        <button id="pause-btn">暂停</button>
        <button id="reset-btn">重置</button>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        const timerDisplay = document.getElementById('timer-display');
        const startBtn = document.getElementById('start-btn');
        const pauseBtn = document.getElementById('pause-btn');
        const resetBtn = document.getElementById('reset-btn');

        let intervalId;
        let isPaused = true;
        let timeLeft = 1500; // 25 minutes in seconds

        function updateTimer() {
            const minutes = Math.floor(timeLeft / 60);
            const seconds = timeLeft % 60;
            timerDisplay.textContent = `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
        }

        function startTimer() {
            if (isPaused) {
                intervalId = setInterval(() => {
                    if (timeLeft > 0) {
                        timeLeft--;
                        updateTimer();
                    } else {
                        clearInterval(intervalId);
                        alert('时间到!');
                    }
                }, 1000);
                isPaused = false;
            }
        }

        function pauseTimer() {
            if (!isPaused) {
                clearInterval(intervalId);
                isPaused = true;
            }
        }

        function resetTimer() {
            clearInterval(intervalId);
            isPaused = true;
            timeLeft = 1500;
            updateTimer();
        }

        startBtn.addEventListener('click', startTimer);
        pauseBtn.addEventListener('click', pauseTimer);
        resetBtn.addEventListener('click', resetTimer);

        updateTimer();
    </script>
</body>
</html>

结果显示:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值