Particle Logo

在 Astro 中添加 Logo 粒子动画

Astro 默认零 JS 输出。你可以用 client:visible 让粒子组件进入视口时再水合,也可以把免费导出的 HTML 单文件放进 public/ 目录直出。

更新于

方案一:使用 client:visible 按需水合(Pro)

如果你已经在 Astro 项目里启用了 @astrojs/react 或 @astrojs/vue,直接导入从 Particle Logo 工坊 导出的 PixelLogoLoader.tsx 或 PixelLogoLoader.vue,加上 client:visible 指令。这样只有用户滚动到该区域时才执行 Canvas 粒子渲染,不影响首屏加载指标:

---
import { PixelLogoLoader } from '../components/PixelLogoLoader';
---

<!-- Hydrate only when scrolled into view -->
<PixelLogoLoader client:visible variant="condense" height={340} />

方案二:零前端框架依赖(免费版即可)

如果你的 Astro 博客没有安装任何前端框架集成,在工坊导出免费的 HTML5 单文件并存为 public/logo-loader.html,在 .astro 页面中用带 loading="lazy" 的 iframe 引入:

<!-- Zero-JS Astro option using the free HTML5 export in public/logo-loader.html -->
<iframe
  src="/logo-loader.html"
  title="Brand particle logo"
  style="width:100%;height:420px;border:0;border-radius:16px;background:#000;"
  loading="lazy"
></iframe>

想替换动画效果,只需修改导出文件里的 variant 变量。可选值参考效果大全。

进入工坊

其他教程