Erica Du
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    7
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 五金行日曆 ![](https://i.imgur.com/CJ4Hpge.jpg =600x) > [FIVE METAL SHOP CALENDAR 五金行日曆 2020](https://www.shoppingdesign.com.tw/post/view/4618/) 一直很喜歡這本可愛又充滿設計感的傳統日曆,但是礙於懶人個性一定放到明年還在第一頁 太可愛了也會捨不得撕,趁著這次練習 Date(),不如就自己手刻一本。 ## 重點語法 撰寫語法使用 SASS,如果看不習慣的話可以轉譯成 CSS 主要會頻繁使用到以下語法: * **flex** * **transform: translate、skew、scale** * **background: linear-gradient** * **box-shadow** * **text-shadow** **<font color="red">*這次 CodePen 設定 CSS Base 有開啟 Reset</font>** ## 一、分析架構 開始切版之前,首先要分析架構 就像蓋房子一樣,地基要打得穩,房子才能蓋的堅固 如果是初學者,建議可以試著在紙上畫出網頁架構 **外框容器** * calendar:日曆主體,用 `after` 製作厚度 * header:上方裝訂,用 `before` 製作厚度 * hook:掛鉤部分 * body:主要呈現內容 ![](https://i.imgur.com/DU1OuvE.jpg =500x) **資料內容** * month:上方當月月份 * date:今天日期 * fullMonth:小月曆 * week:星期、農曆 * icons:小圖示 ![](https://i.imgur.com/dkzGprg.jpg =500x) ## 二、HTML 切版 框架分析完後,就可以開始切框架 切版時先放入靜態資料,模擬放入資料的狀況,調整樣式也較準確 <font color="red">*****</font> 可以在 css 最上方加入這段,自動把所有物件加上外框 ``` * { outline: 1px solid red } ``` ```htmlmixed= <div id="app"> <div class="calendar"> <div class="header"> <div class="pin"></div> <p>2020</p> <div class="pin"></div> </div> <div class="hook"></div> <div class="body"> <div class="month"> <p>8</p> <p>Aug</p> </div> <div class="date">11</div> <div class="footer"> <div class="fullMonth"> <div class="title">August</div> <table> <tr> <th>...</th> </tr> <tr> <td>...</td> </tr> </table> </div> <div class="week"> <p class="en">tuseday</p> <p class="day">星期二</p> <p class="lunar">農6-22</p> </div> <div class="icons"> <div class="material-icons">wb_sunny</div> <div class="material-icons">cloud</div> <div class="material-icons">brightness_1</div> </div> </div> </div> </div> </div> ``` **小月曆** 的部分會有字體沒辦法再縮小的問題: 1. 可以用 `transform: scale` 來縮小整體 2. 再用 `transform-rigin` 調整中心位置 3. 加上 `ransform: translate` 調整位移 初步完成如下圖: ![](https://i.imgur.com/oH2UXha.png =500x) ## 三、用偽元素製作細節 框架完成後,為避免框架上有太多元件 裝飾性質的東西可以用 `before`、`after` 來完成 ( 下圖綠色部分 ) **月曆厚度** 可以用 `transform: skew` 製作傾斜效果 先用 `scale` 放大會比較好對齊,邊調整位置和角度,讓兩條厚度可以接在一起 ![](https://i.imgur.com/6yZU2u4.png =500x) ## 四、陰影運用 陰影 `box-shadow` 的運用是繪製實物時最重要的部分,可以分為幾種方式: ### 基本陰影堆疊 陰影可以無限堆疊,並且設定不同位移、強度、顏色 依照畫面的需求堆疊出陰影,增加立體感 ![](https://i.imgur.com/pRY5Bhs.png =500x) ### 利用陰影製作重複元素 陰影除了堆疊,也可以用來製作複製元素 利用 **位移變化** 和相同 **陰影強度(模糊效果)**,可以做出頁邊色票 魔鬼藏在細節中,切版最重要的就是細心和耐心 推薦文章: [CSS 模糊效果](https://www.oxxostudio.tw/articles/201407/css-blur.html) ```sass box-shadow: 0 0 2px 1px #79746B, 1px*1 -22px*1 2px 1px #A07F2E, 1px*2 -22px*2 2px 1px #884940, 1px*3 -22px*3 2px 1px #216164, 1px*4 -22px*4 2px 1px #853555, 1px*5 -22px*5 2px 1px #628279, 1px*6 -22px*6 2px 1px #493B62, 1px*7 -22px*7 2px 1px #772C22, 1px*8 -22px*8 2px 1px #436251, 1px*9 -22px*9 2px 1px #0B6575, 1px*10 -22px*10 2px 1px #99834C, 1px*11 -22px*11 2px 1px #4D4229, 1px*12 -22px*12 2px 1px #89425A, 1px*13 -22px*13 2px 1px #5A4C6A, 1px*14 -22px*14 2px 1px #975B4B ``` ![](https://i.imgur.com/WVFgEVM.png =500x) ## 五、抓取時間 加上顏色和相關細節設定後,就要來加入時間內容 ### 日期、星期 ```javascript= const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] const days = ['日', '一','二','三','四','五','六'] const en = ['sunday', 'monday','tuseday','wednesday','thursday','friday','saturday'] const today = new Date() const yy = today.getFullYear() const mm = today.getMonth() const dt = today.getDate() const dy = today.getDay() function render (){ getElemt('.header p').innerHTML = `${yy}` getElemt('.month').innerHTML = ` <p>${mm + 1}</p> <p>${months[mm].substring(0, 3)}</p>` // 取出前三個字元 getElemt('.date').innerHTML = `${dt}` getElemt('.fullMonth .title').innerHTML = `${months[mm]}` getElemt('.week .day').innerHTML = `星期${days[dy]}` getElemt('.week .en').innerHTML = `${en[dy]}` } ``` ### 電子鐘 ```javascript= function timer (){ let newTime = new Date() let h = newTime.getHours() let m = newTime.getMinutes() let s = newTime.getSeconds() let hour = ((h < 10) ? '0' : '') + h let min = ((m < 10) ? '0' : '') + m let sec = ((s < 10) ? '0' : '') + s getElemt('.timer').innerHTML = `${hour}:${min}:${sec}` } setInterval(timer, 1000) ``` ## 六、製作小月曆 ### 取得當月份總天數 * 當月的第32天 - 當天日期 = 當月最後一天 * 舉栗:8月的第32天為9/1,32-1=31 * 得到8月的最後一天為31號,當月有31天 ```javascript= function daysInMonth(m, y) { return 32 - new Date(y, m, 32).getDate() } ``` ### 小月曆本人 參考資料:[Challenge of building a Calendar with Pure JavaScript](https://link.medium.com/1UTiIVbCP8) ```javascript= function calendar (year, month){ let firstDay = (new Date(year, month)).getDay() // 取得當月第一天 let date = 1 // 當月第一天/日期,起始值 for( let r=0; r<6; r++ ) { // 最多6行 let row = createElemt('tr') let cell, cellText for ( let i=0; i<7; i++) { // 一星期7天,最多7列 if( r === 0 && i < firstDay ) { // 第0列,且當週 < 7天,填補空格 cell = createElemt('td') row.appendChild(cell) } else if ( date > daysInMonth(month, year) ) { // 若當天日期 > 當月最後一天,跳出現在迴圈 break } else { cell = createElemt('td') cellText = document.createTextNode(date) // 補上空格並填入日期 if( year === yy && month === mm && date === dt ) { cell.classList.add('now') // 今天日期加上 now } cell.appendChild(cellText) row.appendChild(cell) date ++ } } getElemt('.fullMonth table').appendChild(row) } } ``` ### 農曆計算 參考資料:[1900年至2100年公历、农历互转Js代码](https://blog.jjonline.cn/userInterFace/173.html) ## 七、關燈效果 ![](https://i.imgur.com/EDIaxAp.png =x420)![](https://i.imgur.com/XGvytrh.png =x420) 運用 `text-shadow` 的堆疊方式就可以做出文字發光效果 開關的部分我用 `checkbox` 和 `label` 做簡單的切換 * HTML ```htmlmixed= <div class="lightBtn"> <input id="btn" type="checkbox"/> <label for="btn"> <span class="off">關燈</span> <span class="on">開燈</span> </label> </div> ``` * SASS ```sass= #btn display: none // 隱藏 checkbox #btn:checked ~ label // 點選 checkbox 後,變更 label 內設定 .off // 關燈樣式 ON .on // 開燈樣式 OFF ``` * JavaScript ```javascript= const btn = getElemt('#btn') btn.addEventListener('click', () => { if( btn.checked ) { getElemt('body').classList.add('active') } else { getElemt('body').classList.remove('active') } }) ``` --- DEMO:[Calendar 五金行日曆](https://codepen.io/ericadu/full/GRZJjjE)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully