vue-confetti
:tada: A Vue component for dropping confetti :tada:
View the demo
Installation
npm install vue-confetti --save
Usage
<template>
<main>
<button @click="start">Start</button>
<button @click="stop">Stop</button>
<button @click="love">Show some love</button>
</main>
</template>
<script>
import Vue from 'vue'
import VueConfetti from 'vue-confetti'
Vue.use(VueConfetti)
export default {
methods: {
start() {
this.$confetti.start();
},
stop() {
this.$confetti.stop();
}
love() {
this.$confetti.update({
shape: 'heart',
colors: [
'red',
'pink',
'#ba0000'
],
});
}
}
}
</script>
Configuration
The following options can be passed to $confetti.start()
or $confetti.update()
:
Property | Type | Description | Default |
---|
shape | String | The shape of the confetti ('circle' , 'rect' , 'heart' or 'image' ). | 'circle' |
size | Number | The size of the particles (should be a positive number). | 10 |
dropRate | Number | The speed at which the particles fall. | 10 |
colors | Array | The confetti colors. | ['DodgerBlue', 'OliveDrab', 'Gold', 'pink', 'SlateBlue', 'lightblue', 'Violet', 'PaleGreen', 'SteelBlue', 'SandyBrown', 'Chocolate', 'Crimson'] |
image | String | The path to a custom image or SVG to use as the particle. Note that shape must be set to image . | null |
canvasId | String | The ID for a custom canvas element (the default is to append a canvas to the <body> element). | null |
particlesPerFrame | Number | The number of particles to drop per animation frame. | 2 |
Examples
Red and pink hearts:
$confetti.start({
shape: 'heart',
colors: [
'red',
'pink',
'#ba0000',
],
});
Custom image:
$confetti.start({
shape: 'image',
image: 'http://placekitten.com/50/50',
});
Custom canvas:
$confetti.start({
canvasId: 'my-custom-canvas',
});
Alternative particles per frame, drop rate and size:
$confetti.start({
particlesPerFrame: 0.25,
dropRate: 3,
size: 5,
});
Development
The following scripts are available for local development:
npm run test
npm run dev
npm run build
npm run demo
Note that vue-confetti enforces
conventional commits
to help automate the release process. Whenever code is merged into master the next
semantic version number is automatically determined, a
changelog generated and the release published.