For Tailwind CSS v3 docs, click here.

五彩纸屑

一个五彩纸屑动画的Vue组件。

通过 CLI 安装

npm
pnpm
bun
yarn
npx shadcn-vue@latest add "https://registry.inspira-ui.com/confetti.json"

手动安装

Install the dependencies

npm
pnpm
bun
yarn
npm install canvas-confetti
npm install -D @types/canvas-confetti

复制并粘贴以下代码:

Confetti.vue
ConfettiButton.vue

示例

Basic

Random Direction

Fireworks

Side Cannons

API

Components props

Confetti

Prop 名称类型默认值描述
optionsConfettiOptions{}Options for individual confetti bursts.
globalOptionsConfettiGlobalOptions{}Global options for the confetti instance (e.g., resize behavior).
manualstartbooleanfalseIf true, confetti won't start automatically on mount.

ConfettiOptions

Property类型默认值描述
particleCountnumber50The number of confetti particles to launch.
anglenumber90The angle in degrees at which to launch the confetti.
spreadnumber45The spread in degrees of the confetti.
startVelocitynumber45The initial velocity of the confetti particles.
decaynumber0.9The rate at which confetti particles slow down.
gravitynumber1The gravity applied to confetti particles.
driftnumber0The horizontal drift applied to confetti particles.
ticksnumber200The number of animation frames the confetti should last.
origin{ x: number, y: number }{ x: 0.5, y: 0.5 }The origin point (from 0 to 1) of the confetti emission.
colorsstring[]['#26ccff', '#a25afd', '#ff5e7e', '#88ff5a', '#fcff42', '#ffa62d', '#ff36ff']Array of color strings in HEX format for the confetti particles.
shapesstring[]['square', 'circle']Array of shapes for the confetti particles.
scalarnumber1Scaling factor for confetti particle sizes.
zIndexnumber100The z-index value for the confetti canvas element.
disableForReducedMotionbooleanfalseDisables confetti for users who prefer reduced motion.
useWorkerbooleantrueUse a Web Worker for better performance.
resizebooleantrueWhether to automatically resize the canvas when the window resizes.
canvasHTMLCanvasElement | nullnullCustom canvas element to draw confetti on.
gravitynumber1The gravity applied to confetti particles.
driftnumber0The horizontal drift applied to particles.
flatbooleanfalseIf true, confetti particles will be flat (no rotation or 3D effect).

ConfettiButton

Prop 名称类型默认值描述
optionsConfettiOptions & { canvas?: HTMLCanvasElement }{}Options for confetti when the button is clicked.

功能特性

  • Confetti Animation: Easily add confetti animations to your Vue application.
  • Customizable Options: Configure both global and individual options for confetti behavior.
  • Manual Control: Choose whether to start confetti automatically or manually trigger it.
  • Button Integration: Use the ConfettiButton component to trigger confetti on button clicks.

感谢