A Simple Fireworks Animation With JavaScript | fireworks-js

fireworks-js is a JavaScript library that adds configurable fireworks animations with sound effects to your webpage.

Features

  • 🔥 Zero dependencies
  • ⚙️ Flexible configuration
  • 📦 Lightweight (~3.0kB gzipped)
  • 📜 Supports TypeScript type definition

Must Read: A Vue Hook Composable For Playing Sound Effects

How to make use of it:

1. Install and import the fireworks-js as an ES module.

# Yarn
$ yarn add fireworks-js

# NPM
$ npm i fireworks-js

import { Fireworks } from 'fireworks-js'

2. Or load the fireworks.js JavaScript library from the dist folder.

<script src="dist/fireworks.js"></script>

3. Create a container on which you need to render the firework animation.

<div class="fireworks-example"></div>

4. Initialize the fireworks-js library on the container factor and config the firework animation utilizing the next props.

const fireworks = new Fireworks({
      target: document.querySelector('.fireworks-example'),
      hue: 120,
      startDelay: 1,
      minDelay: 20,
      maxDelay: 30,
      speed: 5,
      acceleration: 1.15,
      friction: 0.88,
      gravity: 1,
      particles: 65,
      trace: 3,
      explosion: 6,
      boundaries: {
        top: 70,
        bottom: container.clientHeight,
        left: 70,
        right: container.clientWidth
      },
      sound: {
        enable: true,
        list: [
          'explosion0.mp3',
          'explosion1.mp3',
          'explosion2.mp3'
        ],
        min: 4,
        max: 8
      }
})

5. Start the firework animation.

fireworks.start();

6. Pause the firework animation.

fireworks.pause()

7. Stop the firework animation.

fireworks.stop()

8. Clear the firework animation.

fireworks.clear()

Must Read: Virtual Keyboard Typing Sound Built With Pure Javascript

API

.start()

Start fireworks.

.stop()

Stop fireworks.

.pause()

Start/stop fireworks.

.clear()

Cleaning the canvas from fireworks.

.updateOptions(options)

Force update fireworks options.
Type: options

.updateSize(sizes)

Force update canvas size.
Type: sizes

.updateBoundaries(boundaries)

Force update canvas boundaries.
Type: boundaries

Options

Note
The options is optional, as are each of its properties.

Must Read: Javascript Library for Old Typewriter Text Animation Effect | Typewriterjs

PropertyTypeDefault
hueobjecthue
rocketsPointobjectrocketsPoint
mouseobjectmouse
boundariesobjectboundaries
soundobjectsound
delayobjectdelay
brightnessobjectbrightness
decayobjectdecay
lineWidthobjectlineWidth
lineStylestringround
explosionnumber5
opacitynumber0.5
accelerationnumber1.05
frictionnumber0.95
gravitynumber1.5
particlesnumber50
traceLengthnumber3
flickeringnumber50
intensitynumber30
traceSpeednumber10
intensitynumber30
autoresizebooleantrue
PackageDescription
fireworks-jsVanilla JS
@fireworks-js/reactReact component
@fireworks-js/preactPreact component
@fireworks-js/solidSolid component
@fireworks-js/vueVue 3 component
@fireworks-js/svelteSvelte component
@fireworks-js/angularAngular component
@fireworks-js/webWeb components

See Also –

A Simple Fireworks Animation With a JavaScript And Canvas Library
A JavaScript Library For Simple Toast Popups Based On Bootstrap 5 | Toaststrap
jQuery Plugin that Allows the User to Specify a Value or Range of Values | roundSlider


See Demo And Download

fireworks-js

Official Website(crashmax-off): Click Here

This superior jQuery/javascript plugin is developed by crashmax-off. For extra Advanced usage, please go to the official website.

Related Posts

drag-drop-file-5x5-jq-uploader

Responsive Drag and Drop File Uploader/Download Plugin | 5x5_jq_uploader

5x5_jq_uploader plugin can be used to instantly create a drop file area and file queue with a little bit of preparation. Bootstrap is used for responsive planning…

Bootstrap-Dark-Mode

Stylesheet For Implementing Dark Mode with Bootstrap

Bootstrap Dark Mode provides a style sheet and two texts that allow you to implement Dark Mode on your website. Initially loaded based on user preferences, can…

responsive-navigation-menu

Multi-purpose Navigation Menu for Javascript Library | jQuery Corenav

coreNavigation is a multipurpose navigation menu for a jquery based javascript library, comes with more style, and is easy to integrate. 11 Default Menu 2 Responsive Navigation…

Simple-Multi-Select-Dropdown-Pure-Vanilla-Javascript

Simple Multi-Select Dropdown Pure Vanilla Javascript | multiSelect.js

MultiSelect.js is a simple, clean, and progressive JavaScript library designed for easy integration with any type of project or system. The design was heavily influenced by the…

Confetti-Falling-Animation-Effect-party

Confetti Falling Animation Effect In JavaScript | party.js

Party.js is a JavaScript library to brighten user site experience with visual effects! Celebrate success with dom confetti! The library is written in TypeScript and compiled into…

how-to-create-popup-in-html-with-css

How To Create A Popup in HTML with CSS

How to create popup in html with css – Popup without JavaScript is an elegant pop-up panel component with an animated scale, written in CSS. Have you…