Search

Back

Copy Link

Library

/

Free

/

5

Confetti

5

Confetti

FREE

Not loading? Preview

Made by

tsParticles

override

click

Override

Confetti

Copy

Override

Copied to Clipboard!

Instructions

Code Preview

import type { ComponentType } from "react"
import confetti from "canvas-confetti"

const defaults = {
    spread: 360,
    ticks: 100,
    gravity: 0,
    decay: 0.94,
    startVelocity: 30,
}

function shoot(x: number, y: number) {
    confetti({
        ...defaults,
        particleCount: 30,
        scalar: 1.2,
        shapes: ["circle", "square"],
        colors: ["#a864fd", "#29cdff", "#78ff44", "#ff718d", "#fdff6a"],
        origin: { x: x / window.innerWidth, y: y / window.innerHeight },
    })

    confetti({
        ...defaults,
        particleCount: 20,
        scalar: 2,
        shapes: ["text"],
        shapeOptions: {
            text: {
                value: ["🦄", "🌈"],
            },
        },
        origin: { x: x / window.innerWidth, y: y / window.innerHeight },
    })
}

export function withClick(Component): ComponentType {
    return (props) => {
        const handleClick = (event) => {
            const { clientX, clientY } = event
            shoot(clientX, clientY)
            setTimeout(() => shoot(clientX, clientY), 100)
            setTimeout(() => shoot(clientX, clientY), 200)
        }

        return (
            <Component {...props} onClick={handleClick}>
                {props.children}
            </Component>
        )
    }
}
export function withHover(Component): ComponentType {
    return (props) => {
        const handleHover = (event) => {
            const { clientX, clientY } = event
            shoot(clientX, clientY)
            setTimeout(() => shoot(clientX, clientY), 100)
            setTimeout(() => shoot(clientX, clientY), 200)
        }

        return (
            <Component {...props} onMouseEnter={handleHover}>
                {props.children}
            </Component>
        )
    }
}

Terms of Use for Free Assets

By accessing and using this Framer Override Library, you agree to the following terms:

All code snippets provided are available for your personal and professional use. This includes personal websites, client projects, and other website projects in Framer. You are strictly prohibited from sharing, redistributing, selling these code snippets, or creating derivative works for resale or distribution. Unauthorized sharing, distribution, or selling of these code snippets is a breach of these terms and may result in termination of your access to this library, along with potential legal action.