v2.1.8
  • Get Started
  • Components
  • Composables
  • Typography
  • GitHub
  • Overview
  • defineShortcuts
  • useConfetti
  • useOverlay
  • useToast
  • b24icons
  • b24jssdk
Use our Nuxt starter
v2.1.8
  • Docs
  • Components
  • Composables
  • Typography

useConfetti

Performant confetti animation in the browser
GitHub
Demo
canvas-confetti

Usage

Use the auto-imported useConfetti composable to programmatically control canvas-confetti.

<script setup lang="ts">
const confetti = useConfetti()
</script>
  • The useConfetti composable is created using createSharedComposable, ensuring that the same canvas-confetti is shared across your entire application.
Since canvas-confetti works with the DOM, make sure your code only runs on the client.

API

fire(options?: confetti.Options) => Promise<undefined> | null

Fire some confetti.

<script setup lang="ts">
const confetti = useConfetti()

function fireConfetti(): void {
  confetti.fire()
}
</script>

create(canvas?: HTMLCanvasElement, options?: GlobalOptions) => CreateTypes

This method creates an instance of the confetti function that uses a custom canvas.

Use if you need to specify your own parameters for confetti.

<script setup lang="ts">
const confetti = useConfetti()

function fireConfettiWithOptions(): void {
  confetti.create()
  confetti.fire({
    particleCount: 100,
    spread: 70,
    origin: { y: 0.6 }
  })
}
</script>

Or like this. Specify your own Canvas.

<script setup lang="ts">
import { ref } from 'vue'
  
const myCanvas = ref<HTMLCanvasElement | undefined>()
const confetti = useConfetti()

function fireAtPlace(): void {
  const confettiInstance = confetti.create(myCanvas.value, { resize: true })
  confettiInstance({
    spread: 70
  })
}
</script>
<template>
  <B24Button label="custom canvas" color="link" depth="dark" @click.stop="fireAtPlace" />
  <div>
    <canvas ref="myCanvas" class="h-64 w-1/2" />
  </div>
</template>

Example

Here's a complete example of how to use the useConfetti composable:

Simple use

{
  "wait": "Loading client-side content..."
}

With some options

{
  "wait": "Loading client-side content..."
}

At custom place

{
  "wait": "Loading client-side content..."
}

defineShortcuts

A composable to assign keyboard shortcuts in your app.

useOverlay

A composable to programmatically control overlays in App.

On this page

  • Usage
  • API
  • Example
    • Simple use
    • With some options
    • At custom place
Releases
Published under MIT License.

Copyright © 2024-present Bitrix24