Particle Logo

在 Vue 3 專案中加入 Logo 粒子動畫

Vue 匯出為內建 Logo 點陣的單檔案元件,可作為首頁主視覺或載入畫面,並以屬性彈性控制。

更新於

您會取得什麼

1. 匯出元件

  1. 開啟工坊。
  2. 上傳 Logo:點擊選擇 PNG、SVG、JPG 或 WebP 檔案,也可直接拖曳至頁面或按 Ctrl+V / ⌘+V 貼上。透明或純色背景效果最佳;若有缺漏可調整點陣密度與提取閾值。
  3. 從 16 種效果中任選一款,調整粒子大小、形狀(方塊或圓點)與速度。
  4. 點擊匯出程式碼,切至 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

參數類型預設值用途說明
variantstring匯出時選擇的效果播放哪種粒子效果,可選值見下表
widthnumber | string'100%'數值單位為像素
heightnumber | string420數值單位為像素
autoPlaybooleantrue自動循環播放:每輪 duration 秒,之後停頓 1.2 秒
durationnumber3.2每輪動畫秒數
progressnumber無0 至 100;傳入後將依照該進度值顯示,停止自動播放
colorsstring[]匯出時選擇的配色粒子配色;自帶原色的採樣點將保留原圖色彩
particleSizenumber匯出時的大小基礎粒子尺寸,會隨容器大小等比縮放
particleShape'square' | 'circle'匯出時的形狀方塊或圓點粒子
speedMultipliernumber匯出時的速度粒子朝目標點移動的速率倍率
interactivebooleantrue是否開啟滑鼠互動:經過推開粒子,點擊觸發衝擊波

更動 variant、colors、particleSize 或 particleShape 時會重建粒子。variant 可選值:

variant 值效果
condense量子凝聚態
mobius-flow莫比烏斯拓撲光流
vortex星系引力坍縮
scan全息光柵斷層掃描
diffusion-denoise擴散降噪重構
flux-wave超導磁通漣漪
swarm-assembly奈米蜂群智慧組裝
gravitational-slingshot引力彈弓時間逆流
cymatics-resonance克拉尼聲波共振
curl-flow量子旋度流場
orbital-sphere3D 球面經緯展開
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. 效能與無障礙

<script setup lang="ts">
const reduceMotion =
  typeof window !== 'undefined' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
</script>

<template>
  <PixelLogoLoader :progress="reduceMotion ? 100 : undefined" />
</template>
進入工坊

其他教學