iT邦幫忙

2025 iThome 鐵人賽

DAY 24
1

前言

這次要介紹的 Animate UI – Star Background,就像在你的畫面上灑下一整片星河,
讓靜態的頁面瞬間多了點浪漫氣息~

不需要望遠鏡,也不必上太空,只要透過幾行指令安裝、幾個參數調整,就能讓你的網站在夜色中閃爍登場 ✨。

準備好和我一起探索這片互動式星空了嗎?🚀

Star Background

Star Background

  1. 使用 Shadcn CLI 加入 Star Background

    npx shadcn@latest add @animate-ui/components-backgrounds-stars
    
  2. Import 元件並將元件放在想要的位置上

    import { StarsBackground } from '@/components/animate-ui/components/backgrounds/stars';
    
    <StarsBackground>...</>
    
  3. 若還有想要微調,可以增加更多參數 (? 表示為選填參數)

StarsBackgroundProps

參數 參數型態 說明
factor number 控制星星的分布密度,值越大星星越多,預設為 0.05,但這個參數我個人覺得影響不大 🤔
speed number 控制星星的移動速度,預設為 50,越小越快,越大移動速度越慢
transition SpringOptions 控制動畫的彈性與阻尼參數,預設為 { stiffness: 50, damping: 20 }
starColor string 星星的顏色,預設為 #fff,可支援 white, black, yellow 等寫法
pointerEvents boolean 是否允許滑鼠事件穿透背景,預設為 true
className string 外層容器的自訂樣式 class 名稱

小結

今天我們了解 Animate UI 的 Star Background,是不是有種置身於宇宙的感覺鴨 🌌
透過 shadcn CLI,就能輕鬆在網頁背景上灑滿閃閃發光的星星 ✨,同時可調整多個參數,像是星星的數量、速度、顏色等,讓你能自由打造專屬的星空場景 💫

Reference


上一篇
Day 23 - Animate UI Hexagon Background
下一篇
Day 25 - Animate UI Sidebar
系列文
讓你的 UI 動起來:Animate-UI 初探26
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0
chiaominchang222
iT邦新手 5 級 ‧ 2025-10-08 22:39:12

! 可以許願月亮嗎XD

adsfaaron iT邦新手 5 級 ‧ 2025-10-09 11:56:08 檢舉

https://ithelp.ithome.com.tw/upload/images/20251009/20141726C7D2pvC7pO.png

月亮來了🌛

挖好美

1
AndyAWD
iT邦新手 2 級 ‧ 2025-10-08 23:01:41

自己的星星自己做

adsfaaron iT邦新手 5 級 ‧ 2025-10-09 11:59:17 檢舉

沒錯 還可以馬賽克化🤣
components/animate-ui/components/backgrounds/stars.tsx 中 54-61 修改

<div
    className="absolute bg-transparent rounded-full"
    style={{
      width: `${size}px`,
      height: `${size}px`,
      boxShadow: boxShadow,
    }}
/>

星星就可以變成想要的形狀了 🎉

來點什麼星座好呢(不要再亂許願了XD

1
RayYuanLiu
iT邦新手 5 級 ‧ 2025-10-09 09:43:54

讓我回地球

adsfaaron iT邦新手 5 級 ‧ 2025-10-09 12:00:09 檢舉

Elon 半路不會放你下船的 😆

我要留言

立即登入留言