開發者們大家好!我很高興分享我的最新項目:月曆。該專案非常適合任何想要用 JavaScript 創建實用且具有視覺吸引力的日曆的人。無論您是有興趣為網站添加日曆功能,還是只是想提高您的 JavaScript 技能,這個專案都將是您投資組合中的寶貴補充。
月曆是一款基於網絡的應用程序,可顯示當前月份、突出顯示今天的日期並準確排列一周中的日期。該專案展示如何使用 JavaScript 動態生成日曆,並結合使用 HTML 和 CSS 建立的時尚且響應式的介面。
以下是項目結構的概述:
Month-Calendar/ ├── index.html ├── style.css └── script.js
要開始該項目,請按照以下步驟操作:
複製儲存庫:
git clone https://github.com/abhishekgurjar-in/Month-Calendar.git
開啟專案目錄:
cd Month-Calendar
運行項目:
index.html 檔案定義了月曆的結構,包括月份顯示和日期的網格佈局。這是一個片段:
8b05045a5be5764f313ed5b9168a17e6 49099650ebdc5f3125501fa170048923 93f0f5c25f18dab9d176bd4f6de5d30e 7c8d9f814bcad6a1d7abe4eda5f773e5 acd8feeb3a0ea7477b979779de32785a 26faf3d1af674280d03ba217d87e9421 b2386ffb911b14667cb8f0f91ea547a7Month Calendar6e916e0f7d1e588d4f442bf645aedb2f af75c476cdb7e6c074ca6da9b40841de 90392ec4442ad9ff612213ec639da4832cacc6d41bbb37262a98f745aa00fbf0 9c3bca370b5104690d9ef395f2c5f8d1 6c04bd5ca3fcae76e30b72ad730ca86d 4883ec0eb33c31828b7c767c806e14c7 924ff17625d603f964501dd897c96cc6 4a249f0d628e2318394fd9b75b4636b1Month Calendar473f0a7621bec819994bb5020d29372a 16b28748ea4df4d9c2150843fecfba68 6a0cba8356a55c4a6e47746d431e6421 418883615a2e79b9926c86666863ce0d 5f41073e18caf0aa09116baf33d01f47 4a249f0d628e2318394fd9b75b4636b1473f0a7621bec819994bb5020d29372a e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3 16b28748ea4df4d9c2150843fecfba68 16b28748ea4df4d9c2150843fecfba68 639769261d891863793f213a2da06288 dc6dce4a544fdca2df29d5ac0ea9906bMon16b28748ea4df4d9c2150843fecfba68 dc6dce4a544fdca2df29d5ac0ea9906bTue16b28748ea4df4d9c2150843fecfba68 dc6dce4a544fdca2df29d5ac0ea9906bWed16b28748ea4df4d9c2150843fecfba68 dc6dce4a544fdca2df29d5ac0ea9906bThu16b28748ea4df4d9c2150843fecfba68 dc6dce4a544fdca2df29d5ac0ea9906bFri16b28748ea4df4d9c2150843fecfba68 dc6dce4a544fdca2df29d5ac0ea9906bSat16b28748ea4df4d9c2150843fecfba68 dc6dce4a544fdca2df29d5ac0ea9906bSun16b28748ea4df4d9c2150843fecfba68 16b28748ea4df4d9c2150843fecfba68 97a12517d2546b2575274c1d8a6e171e16b28748ea4df4d9c2150843fecfba68 16b28748ea4df4d9c2150843fecfba68 ffd6ba4147bda351239915f463e46e38 e388a4556c0f65e1904146cc1a846beeMade with ❤️ by Abhishek Gurjar94b3e26ee717c64999d7867364b1b4a3 16b28748ea4df4d9c2150843fecfba68 16b28748ea4df4d9c2150843fecfba68 36cc49f0c466276486e50c850b7e4956 73a6ac4ed44ffec12cee46588e518a5e
style.css 檔案設定月曆的樣式,使其既有吸引力又響應靈敏。以下是一些關鍵樣式:
* { margin: 0; padding: 0; font-family: sans-serif; box-sizing: border-box; } .container { width: 100%; height: 100vh; background-color: salmon; display: flex; justify-content: center; align-items: center; flex-direction: column; } .header { margin: 20px; color: white; text-align: center; } .calendar { background-color: black; color: lightgray; width: 450px; height: 520px; border-radius: 10px; box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.4); } .month { width: 100%; height: 120px; background-color: lightseagreen; display: flex; justify-content: center; align-items: center; text-align: center; border-radius: 10px 10px 0 0; } .month h1 { font-size: 30px; font-weight: 400; text-transform: uppercase; } .month p { font-size: 16px; } .weekdays { width: 100%; height: 50px; display: flex; } .weekdays div { font-size: 15px; font-weight: bold; letter-spacing: 1px; width: 100%; display: flex; align-items: center; justify-content: center; } .days { width: 100%; display: flex; flex-wrap: wrap; padding: 2px; } .days div { font-size: 14px; margin: 3px; width: 57.5px; height: 50px; display: flex; justify-content: center; align-items: center; } .days div:hover:not(.empty) { border: 2px solid gray; cursor: pointer; } .today { background-color: lightseagreen; } .footer { margin-top: 70px; color: white; text-align: center; }
script.js 檔案包含產生行事曆和反白顯示目前日期的邏輯。這是一個片段:
const monthEl = document.querySelector(".date h1"); const fullDateEl = document.querySelector(".date p"); const daysEl = document.querySelector(".days"); const monthInx = new Date().getMonth(); const lastDay = new Date(new Date().getFullYear(), monthInx + 1, 0).getDate(); const firstDay = new Date(new Date().getFullYear(), monthInx, 1).getDay() - 1; const months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ]; monthEl.innerText = months[monthInx]; fullDateEl.innerText = new Date().toDateString(); let days = ""; for (let i = firstDay; i > 0; i--) { days += `edfd5fc8d5ee204ac4dfe03b945f3c3916b28748ea4df4d9c2150843fecfba68`; } for (let i = 1; i 67a68beefb344083e30784f1b3a9b000${i}16b28748ea4df4d9c2150843fecfba68`; } else { days += `dc6dce4a544fdca2df29d5ac0ea9906b${i}16b28748ea4df4d9c2150843fecfba68`; } } daysEl.innerHTML = days;
您可以在此處查看月曆項目的現場演示。
建立月曆是一個令人愉快的項目,它使我能夠將我的前端開發技能與實用的 JavaScript 功能結合起來。該工具對於在網站上顯示日曆日期非常有用,並且可以成為您的 Web 開發專案的一個很好的補充。我希望你發現它和我一樣有幫助。快樂編碼!
這個專案是我增強 JavaScript 技能和創建功能性 Web 工具之旅的一部分。
以上是建立一個月曆網站的詳細內容。更多資訊請關注PHP中文網其他相關文章!