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 = ...
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 = ...
const el = document.querySelector('.box');
const detonate = prepare(el, config);
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,
center: {x: 123, y: 123},
shouldRemoveEl: true,
color: '#CCCCCC',
distance: 2,
sliceCount: 10,
maxSliceSize: 15,
shatterClass: 'asdf'
};