您會取得什麼
PixelLogoLoader.vue:單檔案<script setup lang="ts">元件,內建 Logo 採樣點陣(最多 1,600 個點)。- 除 Vue 外無需任何依賴,僅在單一 Canvas 上透過 2D API 繪製。
- Vue 匯出需要 Pro 方案。
1. 匯出元件
- 開啟工坊。
- 上傳 Logo:點擊選擇 PNG、SVG、JPG 或 WebP 檔案,也可直接拖曳至頁面或按 Ctrl+V / ⌘+V 貼上。透明或純色背景效果最佳;若有缺漏可調整點陣密度與提取閾值。
- 從 16 種效果中任選一款,調整粒子大小、形狀(方塊或圓點)與速度。
- 點擊匯出程式碼,切至 Vue 3 元件 分頁並點選下載檔案(或複製程式碼)。此格式需要 Pro 方案。
2. 加入專案
將檔案存為 src/components/PixelLogoLoader.vue,接著使用:
<script setup lang="ts">
import PixelLogoLoader from './components/PixelLogoLoader.vue';
</script>
<template>
<PixelLogoLoader :height="420" />
</template>
預設寬度為容器的 100%、高 420 px,Logo 縮放至容器 72% 內並置中。外框採黑底、16 px 圓角與細邊框,可於底部 .pixel-loader-container 修改樣式。
3. 屬性 Props
| 參數 | 類型 | 預設值 | 用途說明 |
|---|---|---|---|
variant | string | 匯出時選擇的效果 | 播放哪種粒子效果,可選值見下表 |
width | number | string | '100%' | 數值單位為像素 |
height | number | string | 420 | 數值單位為像素 |
autoPlay | boolean | true | 自動循環播放:每輪 duration 秒,之後停頓 1.2 秒 |
duration | number | 3.2 | 每輪動畫秒數 |
progress | number | 無 | 0 至 100;傳入後將依照該進度值顯示,停止自動播放 |
colors | string[] | 匯出時選擇的配色 | 粒子配色;自帶原色的採樣點將保留原圖色彩 |
particleSize | number | 匯出時的大小 | 基礎粒子尺寸,會隨容器大小等比縮放 |
particleShape | 'square' | 'circle' | 匯出時的形狀 | 方塊或圓點粒子 |
speedMultiplier | number | 匯出時的速度 | 粒子朝目標點移動的速率倍率 |
interactive | boolean | true | 是否開啟滑鼠互動:經過推開粒子,點擊觸發衝擊波 |
更動 variant、colors、particleSize 或 particleShape 時會重建粒子。variant 可選值:
| variant 值 | 效果 |
|---|---|
condense | 量子凝聚態 |
mobius-flow | 莫比烏斯拓撲光流 |
vortex | 星系引力坍縮 |
scan | 全息光柵斷層掃描 |
diffusion-denoise | 擴散降噪重構 |
flux-wave | 超導磁通漣漪 |
swarm-assembly | 奈米蜂群智慧組裝 |
gravitational-slingshot | 引力彈弓時間逆流 |
cymatics-resonance | 克拉尼聲波共振 |
curl-flow | 量子旋度流場 |
orbital-sphere | 3D 球面經緯展開 |
matrix-rain | 賽博矩陣數字雨 |
cyber-glitch | 賽博故障切片 |
manhattan-lattice | 正交晶格步進 |
origami-fold | 鏡像摺紙展開 |
helix-weave | 利薩如雙螺旋 |
biolum-pulse | 生物螢光脈動 |
glyph-dissolve | 字元群翼消散 |
4. 作為載入畫面
傳入 progress 後粒子只會移動至對應進度,載入達 100 時 Logo 剛好成形:
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import PixelLogoLoader from './components/PixelLogoLoader.vue';
const progress = ref(0);
const ready = ref(false);
onMounted(async () => {
// 替換成您自己的載入步驟
const steps = [() => fetch('/api/user'), () => fetch('/api/projects')];
for (let i = 0; i < steps.length; i++) {
await steps[i]();
progress.value = ((i + 1) / steps.length) * 100;
}
ready.value = true;
});
</script>
<template>
<PixelLogoLoader v-if="!ready" :progress="progress" :height="360" />
<main v-else>…</main>
</template>
5. Nuxt 與伺服器端渲染 (SSR)
元件僅於 onMounted 啟動繪製,SSR 階段僅輸出空容器;如遇水合警告可用 Nuxt 的 <ClientOnly> 包裹。
6. 效能與無障礙
- 元件於
onBeforeUnmount停止 requestAnimationFrame 並釋放 ResizeObserver。 - 單元件最多 1,600 顆粒子,低階行動裝置請避免同時掛載多個實例。
- 若需響應系統減少動態設定,請傳入固定
progress="100"使粒子直接定型:
<script setup lang="ts">
const reduceMotion =
typeof window !== 'undefined' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
</script>
<template>
<PixelLogoLoader :progress="reduceMotion ? 100 : undefined" />
</template>