Giter Site home page Giter Site logo

saiteja13427 / confetti-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from agezao/confetti-js

0.0 0.0 0.0 193 KB

Easily Generate random confetti for your above-the-fold content

Home Page: https://agezao.github.io/confetti-js/

JavaScript 68.28% CSS 11.42% HTML 20.30%

confetti-js's Introduction

๐ŸŽ‰ Confetti Generator ๐ŸŽ‰

Easily Generate random confetti with javascript and make your design look cooler

Demo ๐Ÿš€

Demo // Examples

Why?

Have you ever seen that cool looking confetti on landing pages and above-the-fold content? We give you the power to create the same effect for free and without the hassle of having to design or code it from scratch.

Installing/Using

๐Ÿ“ฒ Downloading

  • Using npm

      npm install confetti-js --save
  • Direct download -> click here

โž• Add scripts

  • The classic way

    <script src="node_modules/confetti-js/dist/index.min.js"></script>
  • ES6 module

    // At the component you want to use confetti
    import ConfettiGenerator from "confetti-js";

๐Ÿค” How to use it?

After installing the plugin(the topic above), just call-it passing your options:

html

<canvas id="my-canvas"></canvas>

javascript

var confettiSettings = { target: 'my-canvas' };
var confetti = new ConfettiGenerator(confettiSettings);
confetti.render();

You can also pass a canvas element as the target:

var confettiElement = document.getElementById('my-canvas');
var confettiSettings = { target: confettiElement };
var confetti = new ConfettiGenerator(confettiSettings);
confetti.render();

React

React.useEffect(() => {
  const confettiSettings = { target: 'my-canvas' };
  const confetti = new ConfettiGenerator(confettiSettings);
  confetti.render();

  return () => confetti.clear();
}, []) // add the var dependencies or not

done!

Options

Attribute Description Example value Default value
target The Id tag or node of the canvas that will be used 'my-canvas' 'confetti-holder'
max The number of props(confetti) to be rendered 11 80
size Prop size 1.8 1
animate If the confetti should fall false true
respawn If the confetti should be recreated after going off-screen false true
clock The speed confetti fall 50 25
props The type of props(confetti) that should be rendered. In addition to those listed in the default, there's a special "svg" type which requires further configuration and is detailed below. ['circle', 'square'] ['circle', 'square', 'triangle', 'line']
colors The color to be rendered on the confetti. By default, RGB format inside an array. [[0,0,0], [255,255,255]] [[165,104,246],[230,61,135],[0,199,228],[253,214,126]]
start_from_edge Whether the confettis should fall from the top of the screen (or should move up from the bottom) true false
width Canvas width 960 window size
height Canvas height 767 window height
rotate If set to true, SVG and squares will rotate while falling. true false

Special SVG particle type

There is an extra special partical type ("prop") which allows you to render SVGs as confetti particles. For example:

{
  "props": [
    "circle",
    "square",
    { "type": "svg", "src": "site/hat.svg" }
  ]
}

You must specify the type and src properties. There are also a few other configuration properties available to SVG objects:

Attribute Description Example value Default value
size Set the size of the SVG when it renders as a particle. 25 15
weight The probability of this particle being rendered, where 1 is a regular weight, and 0.1 is uncommon. 0.5 1

API

Using the object generated by new ConfettiGenerator() is pretty easy, there're just two main methods actually.

Method Description
render Render the confetti at the config <canvas/>
clear Clear the <canvas/> where the confetti where rendered
var confetti = new ConfettiGenerator();
confetti.render();
//
confetti.clear();

License

You can use/hack/re-distribute/do whatever you want with this for free without having to credit the author or anything. Go on, just do it.

But if you take the time to contribute with the project it would be nice too, just saying :)

Thanks

Special thanks to "Paper Matthew" on codepen for providing the starting point wich I fork to build this. You are awesome.

confetti-js's People

Contributors

agezao avatar danilowoz avatar jonpacker avatar kevingomezdev avatar qortex avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.