🖍️
CSS 排版及動畫效果
  • CSS 排版及動畫效果
  • 1. 簡介
    • 1.1 講者簡介
    • 1.2 課程簡介
    • 1.3 開發工具簡介
  • 2. 棋盤式排版模式 Grid
    • 2.1 基本觀念及術語
    • 2.2 Grid 排版 - Container
    • 2.3 Grid 排版 - Items
  • 3. 多欄排版模式 Column
  • 4. 轉場效果 transition
    • 4.1 第一個 transition
    • 4.2 屬性 transition-property
    • 4.3 期間 transition-duration
    • 4.4 漸變函式 transition-timing-function
    • 4.5 延遲 transition-delay
    • 4.6 transition 縮寫
    • 4.7 練習
  • 5. 動畫效果 animation
    • 5.1 第一個 animation
    • 5.2 關於 keyframes
    • 5.3 同個元素套用多個 animation
    • 5.4 次數 animation-iteration-count
    • 5.5 方向 animation-direction
    • 5.6 延遲 animation-delay
    • 5.7 填滿模式 animation-fill-mode
    • 5.8 播放狀態 animation-play-state
    • 5.9 漸變函式 animation-timing-function
    • 5.10 animation 縮寫
    • 5.11 補充:動畫效果事件(Animation Event)
    • 5.12 練習
  • 6. 作業
  • 7. 第三方動畫效果套件
    • 7.1 Animate.css
    • 7.2 AOS
    • 7.3 CSS Loader
  • 8. 大量練習
  • 9. 其它及參考資料
Powered by GitBook
On this page
  • 什麼是 keyframes
  • keyframes 的群組化寫法
  • 範例
  1. 5. 動畫效果 animation

5.2 關於 keyframes

什麼是 keyframes

keyframes 我們中文稱之為關鍵影格,0% 及 100% 分別都是關鍵影格,同樣的道理,你可以設定任何你想設定的百分比,可以是 10%(動畫執行期間的1/10)、50%(動畫執行期間的一半) 等,這些百分比,都是代表動畫執行期間的關鍵影格。

keyframes 的群組化寫法

觀察以下的寫法,在 33% 與 66% 裡面所撰寫的 css 是相同的:

@keyframes rotation {
  0% {
    transform: rotate(0deg);
  }
  33% {
    transform: rotate(90deg);
  }
  50% {
    transform: rotate(180deg);
  }
  66% {
    transform: rotate(90deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

那我們就可以改成寫如下:

@keyframes rotation {
  0% {
    transform: rotate(0deg);
  }
  33%, 66% {
    transform: rotate(90deg);
  }
  50% {
    transform: rotate(180deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

範例

Previous5.1 第一個 animationNext5.3 同個元素套用多個 animation

Last updated 1 year ago