Skip to content

@moefy-canvas/theme-sparkler

typenpmdownloadsdownloadsGitHub license

🎇 就是现在鼠标周围的粒子效果啦~

Install

bash
pnpm add @moefy-canvas/theme-sparkler

Usage

html
<canvas id="moefy-canvas"></canvas>
ts
import {
   Sparkler,
   SparklerMode,
   type SparklerConfig,
   type CanvasOptions,
   MAX_Z_INDEX,
} from '@moefy-canvas/theme-sparkler'

const themeConfig: SparklerConfig = {
   mode: SparklerMode.TRAIL,
}

const canvasOptions: CanvasOptions = {
   opacity: 1,
   zIndex: MAX_Z_INDEX,
}

const el = document.getElementById('moefy-canvas')
const sparkler = new Sparkler(themeConfig, canvasOptions)
sparkler.mount(el as HTMLCanvasElement)

ThemeConfig

ts
export enum SparklerMode {
   FOLLOW = 'follow',
   TRAIL = 'trail',
}

export interface SparklerConfig extends ThemeConfig {
   mode?: SparklerMode
   numParticles?: number
   sparkleFactor?: number
   particleDurationRange?: [number, number]
   particleDistanceRange?: [number, number]
   particleSizeRange?: [number, number]
}

Released under the MIT License.