0.12.0 ā€¢ Published 5 months ago

js-confetti v0.12.0

Weekly downloads
39
License
MIT
Repository
github
Last release
5 months ago

npm version NPM Downloads npm.io npm bundle size

šŸŽ‰ JavaScript Confetti library

šŸ’„ Supports emojis as confetti āš”ļø Zero dependencies used šŸ¦„ Works without any config, yet configurable šŸ›  Has TypeScript typings šŸ§© Confetti speed adapts to user screen width

Links: GitHub | NPM | Demo

Install

You can install library from NPM using yarn or npm

yarn add js-confetti

Alternatively you can download script from CDN

<script src="https://cdn.jsdelivr.net/npm/js-confetti@latest/dist/js-confetti.browser.js"></script>

and then access JSConfetti global variable

Usage

Initialize instance of JSConfetti class and call addConfetti method

import JSConfetti from 'js-confetti'

const jsConfetti = new JSConfetti()

jsConfetti.addConfetti()

NOTE new JSConfetti() creates HTML Canvas element and adds it to page, so call it only once!

If need to use custom canvas element, you can pass canvas arg to JSConfetti constructor (example)

const canvas = document.getElementById('your_custom_canvas_id')

const jsConfetti = new JSConfetti({ canvas })

Customise confetti

Use emojis as confetti:

jsConfetti.addConfetti({
   emojis: ['šŸŒˆ', 'āš”ļø', 'šŸ’„', 'āœØ', 'šŸ’«', 'šŸŒø'],
})

Customize confetti colors:

jsConfetti.addConfetti({
  confettiColors: [
    '#ff0a54', '#ff477e', '#ff7096', '#ff85a1', '#fbb1bd', '#f9bec7',
  ],
})

Customize confetti radius:

jsConfetti.addConfetti({
  confettiRadius: 6,
})

Customize confetti number:

jsConfetti.addConfetti({
  confettiRadius: 6,
  confettiNumber: 500,
})

Combine different properties:

jsConfetti.addConfetti({
  emojis: ['šŸ¦„'],
  emojiSize: 100,
  confettiNumber: 30,
})

clearCanvas()

Call clearCanvas method to clear canvas

Example:

const jsConfetti = new JSConfetti()

jsConfetti.addConfetti()

// ... 
jsConfetti.clearCanvas()

addConfetti Promise

addConfetti method returns Promise, which is resolved when added confetti dissapears from the user screen due to the gravity physics of confetti

Example:

// async/await
await jsConfetti.addConfetti()
console.log('Confetti animation completed!')

// Promise.then
jsConfetti.addConfetti()
   .then(() => console.log('Confetti animation completed!'))

How to run locally

Install dependencies by Yarn or NPM

yarn install

Run dev script with website build

yarn run dev

License

MIT

0.12.0

5 months ago

0.11.0

2 years ago

0.10.1

2 years ago

0.10.2

2 years ago

0.10.0

2 years ago

0.9.1

2 years ago

0.9.0

3 years ago

0.8.0

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.3

3 years ago

0.1.0

3 years ago

0.0.15

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.1

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.8

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.0

3 years ago