可以用一句話收尾:
進度條就是很直觀的 UI 語言。
a. 靜態版本
最簡單的進度條只需要一個容器 + 一個填充區域:
<div class="w-64 h-4 bg-gray-200 rounded-full overflow-hidden">
<div class="h-full bg-blue-500" style="width: 70%"></div>
</div>
b. 動態版本 (Vue + CSS 變數)
用 Vue 綁定數值 → 寫入 --progress-width:
<template>
<div class="w-64 h-4 bg-gray-200 rounded-full overflow-hidden">
<div class="progress-health" :style="{ '--progress-width': progress + '%' }"></div>
</div>
<button @click="increase">+10%</button>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const progress = ref(0)
const increase = () => {
if (progress.value < 100) progress.value += 10
}
</script>
CSS 部分:
@keyframes progress {
from { width: 0%; }
to { width: var(--progress-width); }
}
.progress-health {
background: var(--gradient-health);
height: 100%;
border-radius: 9999px;
transition: width 0.3s ease-out;
width: var(--progress-width);
}
今天從「為什麼遊戲需要進度條」到「如何做出一個會動、有特效的進度條」都整理了一遍。
下一步,可以把進度條放到 遊戲 Layout 裡,開始讓「RPG 儀表板」真正跑起來。