# js-confetti
**Repository Path**: bigflowerfat/js-confetti
## Basic Information
- **Project Name**: js-confetti
- **Description**: an interesting lib , fork from github
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: main
- **Homepage**: https://loonywizard.github.io/js-confetti/
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2023-03-10
- **Last Updated**: 2023-03-10
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
[](https://badge.fury.io/js/js-confetti)

[](https://www.jsdelivr.com/package/npm/js-confetti)

# 🎉 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](https://github.com/loonywizard/js-confetti) | [NPM](https://www.npmjs.com/package/js-confetti) | [Demo](https://loonywizard.github.io/js-confetti/)
## Install
You can install library from NPM using yarn or npm
```sh
yarn add js-confetti
```
Alternatively you can download script from CDN
```html
```
and then access `JSConfetti` global variable
## Usage
Initialize instance of JSConfetti class and call addConfetti method
```js
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](https://codepen.io/loonywizard-the-selector/pen/wvdPbGm))
```js
const canvas = document.getElementById('your_custom_canvas_id')
const jsConfetti = new JSConfetti({ canvas })
```
## Customise confetti
Use emojis as confetti:
```js
jsConfetti.addConfetti({
emojis: ['🌈', '⚡️', '💥', '✨', '💫', '🌸'],
})
```
Customize confetti colors:
```js
jsConfetti.addConfetti({
confettiColors: [
'#ff0a54', '#ff477e', '#ff7096', '#ff85a1', '#fbb1bd', '#f9bec7',
],
})
```
Customize confetti radius:
```js
jsConfetti.addConfetti({
confettiRadius: 6,
})
```
Customize confetti number:
```js
jsConfetti.addConfetti({
confettiRadius: 6,
confettiNumber: 500,
})
```
Combine different properties:
```js
jsConfetti.addConfetti({
emojis: ['🦄'],
emojiSize: 100,
confettiNumber: 30,
})
```
## clearCanvas()
Call `clearCanvas` method to clear canvas
Example:
```js
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:
```js
// 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
```sh
yarn install
```
Run `dev` script with website build
```sh
yarn run dev
```
## License
MIT