Socket
Socket
Sign inDemoInstall

@ddlab/bomb

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ddlab/bomb

visual explosion effect of a html element


Version published
Weekly downloads
0
Maintainers
1
Install size
85.9 kB
Created
Weekly downloads
 

Readme

Source

Bomb 💣

npm i @ddlab/bomb

A tiny function which creates a visual explosion effect of DOM elements.

💣

Simple example

import {explode} from '@ddlab/bomb';
const config = ... // for config options look at example below

const el = document.querySelector('.box');
el.addEventListener('click', e => explode(el, config));

Performant example

Use prepare -> detonate sequence to save cpu cycles during animation.

import {prepare} from '@ddlab/bomb';
const config = ... // for config options look at example below

const el = document.querySelector('.box');

// place explosives onto the element
const detonate = prepare(el, config);

// detonate on click!
el.addEventListener('click', e => {
    const configChanges = {
        center: {x: e.clientX, y: clientY}
    };
    detonate(configChanges});
});

Config example

The config and every config option is optional. It can be used for explode(), prepare() and detonate() functions. In a case of detonate() it will merge it with previously passed config to prepare() function.

const config = {
    duration: 500, // animation duration
    center: {x: 123, y: 123}, // explosion center. default: target element center
    shouldRemoveEl: true, // toggle for element removal from DOM after explosion. default: false
    color: '#CCCCCC', // background color of shatter. default: background color of target element
    distance: 2, // shatter travel distance - multiplier of slice size. default: 2
    sliceCount: 10, // slice count in one axis. default: 10
    maxSliceSize: 15, // default: 15
    shatterClass: 'asdf' // default: none
};
// now call `detonate(config)` or `prepare(config)` or `detonate(optionalConfing)`

Keywords

FAQs

Last updated on 19 Oct 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc