首頁 > web前端 > css教學 > 主體

建立一個番茄計時器網站

王林
發布: 2024-08-25 20:31:36
原創
282 人瀏覽過

Build a Pomodoro Timer Website

介紹

開發者們大家好!我很高興向大家介紹我的最新項目:番茄計時器。該專案非常適合任何想要提高時間管理技能或練習前端開發的人。番茄計時器是一款簡單但功能強大的工具,旨在幫助您將工作分成幾個有重點的時間間隔,提高工作效率並保持全天的專注。

項目概況

番茄計時器是一款基於網路的應用程序,允許用戶為集中工作設定計時器,通常為 25 分鐘,然後進行短暫休息。這個專案示範如何使用 JavaScript 建立功能計時器,以及使用 HTML 和 CSS 建立乾淨且響應靈敏的使用者介面。

特徵

  • 簡單的計時器介面:極簡設計,顯示倒數計時器和控制。
  • 啟動、停止、重置:使用者可以使用易於使用的按鈕啟動、停止和重置計時器。
  • 通知警報:當計時器達到零時,會觸發警報,表示會話結束。

使用的技術

  • HTML:提供番茄計時器的結構。
  • CSS:設定計時器的樣式,確保簡潔、現代的設計。
  • JavaScript:實作計時器的核心功能,包括倒數邏輯和使用者互動。

專案結構

以下是項目結構的概述:

Pomodoro-Timer/
├── index.html
├── style.css
└── script.js
登入後複製
  • index.html:包含番茄計時器的 HTML 結構。
  • style.css:包含 CSS 樣式,以實現具有視覺吸引力和響應式設計。
  • script.js:管理計時器功能,包括倒數計時和使用者互動。

安裝

要開始該項目,請按照以下步驟操作:

  1. 複製儲存庫

    git clone https://github.com/abhishekgurjar-in/Pomodoro-Timer.git
    
    登入後複製
  2. 開啟專案目錄:

    cd Pomodoro-Timer
    
    登入後複製
  3. 運行項目:

    • 在網頁瀏覽器中開啟index.html檔案以使用番茄計時器。

用法

  1. 在網頁瀏覽器中開啟網站
  2. 點選「開始」按鈕啟動計時器
  3. 停止或重置根據需要使用「停止」和「重置」按鈕來計時。
  4. 專注於你的工作直到計時器為零,然後在開始下一個會話之前短暫休息。

程式碼說明

超文本標記語言

index.html 檔案定義了番茄計時器的結構,包括標題、計時器顯示和控制按鈕。這是一個片段:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Pomodoro Timer</title>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js" defer></script>
  </head>
  <body>
    <div class="container">
      <h1 class="title">Pomodoro Timer</h1>
      <p class="timer" id="timer">25:00</p>
      <div class="button-wrapper">
        <button id="start">Start</button>
        <button id="stop">Stop</button>
        <button id="reset">Reset</button>
      </div>
    </div>
    <div class="footer">
      <p>Made with ❤️ by Abhishek Gurjar</p>
    </div>
  </body>
</html>
登入後複製

CSS

style.css 檔案設定番茄計時器的樣式,確保其具有視覺吸引力和反應能力。以下是一些關鍵樣式:

.container {
  margin: 0 auto;
  max-width: 400px;
  text-align: center;
  padding: 20px;
  font-family: "Roboto", sans-serif;
}

.title {
  font-size: 36px;
  margin-bottom: 10px;
  color: #2c3e50;
}

.timer {
  font-size: 72px;
  color: #2c3e50;
}

button {
  font-size: 18px;
  padding: 10px 20px;
  margin: 10px;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-transform: uppercase;
  transition: opacity 0.3s ease-in-out;
}

button:hover {
  opacity: 0.7;
}

#start {
  background-color: #27ae60;
}

#stop {
  background-color: #c0392b;
}

#reset {
  background-color: #7f8c8d;
}

.footer {
  margin-top: 250px;
  text-align: center;
}
登入後複製

JavaScript

script.js 檔案包含番茄計時器的邏輯,包括倒數機制和處理使用者互動。這是一個片段:

const startEl = document.getElementById("start");
const stopEl = document.getElementById("stop");
const resetEl = document.getElementById("reset");
const timerEl = document.getElementById("timer");

let interval;
let timeLeft = 1500;

function updateTimer() {
  let minutes = Math.floor(timeLeft / 60);
  let seconds = timeLeft % 60;
  let formattedTime = `${minutes.toString().padStart(2, "0")}:${seconds
    .toString()
    .padStart(2, "0")}`;

  timerEl.innerHTML = formattedTime;
}

function startTimer() {
  interval = setInterval(() => {
    timeLeft--;
    updateTimer();
    if (timeLeft === 0) {
      clearInterval(interval);
      alert("Time's up!");
      timeLeft = 1500;
      updateTimer();
    }
  }, 1000);
}

function stopTimer() {
  clearInterval(interval);
}

function resetTimer() {
  clearInterval(interval);
  timeLeft = 1500;
  updateTimer();
}

startEl.addEventListener("click", startTimer);
stopEl.addEventListener("click", stopTimer);
resetEl.addEventListener("click", resetTimer);
登入後複製

現場演示

您可以在此處查看番茄計時器專案的現場演示。

結論

建立番茄計時器是一次有益的經歷,它讓我練習了基本的前端技能,例如 HTML、CSS 和 JavaScript。這個專案是提高生產力的一個很好的工具,我希望它能激勵您創建自己的工具以更好地管理時間。快樂編碼!

製作人員

這個專案是我在前端開發方面持續學習之旅的一部分,重點是創建實用且互動的 Web 應用程式。

作者

  • 阿布舍克·古賈爾
    • GitHub 簡介

以上是建立一個番茄計時器網站的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:dev.to
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!