All Projects → ZachSaucier → Disintegrate

ZachSaucier / Disintegrate

Licence: mit
A small JS library to break DOM elements into animated Canvas particles.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Disintegrate

React Particle Effect Button
Bursting particle effect buttons for React 🎉
Stars: ✭ 1,385 (+451.79%)
Mutual labels:  particles, canvas
Canvas Test
🎮 happy canvas
Stars: ✭ 1,722 (+586.06%)
Mutual labels:  particles, canvas
Knowledge
文档着重构建一个完整的「前端技术架构图谱」,方便 F2E(Front End Engineering又称FEE、F2E) 学习与进阶。
Stars: ✭ 1,620 (+545.42%)
Mutual labels:  canvas, dom
Html To Image
✂️ Generates an image from a DOM node using HTML5 canvas and SVG.
Stars: ✭ 595 (+137.05%)
Mutual labels:  canvas, dom
Layaair discard
This is old LayaAir veriosn writetten by ActionScript 3.0 ,now LayaAir is using TypeScript as the Engine Script,Please use https://github.com/layabox/LayaAir instead.
Stars: ✭ 1,858 (+640.24%)
Mutual labels:  particles, canvas
Curtainsjs
curtains.js is a lightweight vanilla WebGL javascript library that turns HTML DOM elements into interactive textured planes.
Stars: ✭ 1,039 (+313.94%)
Mutual labels:  canvas, dom
Phaser Examples
Contains hundreds of source code examples and related media for the Phaser HTML5 Game Framework.
Stars: ✭ 1,680 (+569.32%)
Mutual labels:  particles, canvas
Canvas Confetti
🎉 on-demand confetti gun
Stars: ✭ 2,394 (+853.78%)
Mutual labels:  particles, canvas
Proton
Javascript particle animation library
Stars: ✭ 1,958 (+680.08%)
Mutual labels:  particles, canvas
Sprite Wxapp
spritejs 小程序版
Stars: ✭ 138 (-45.02%)
Mutual labels:  canvas, dom
Canvas Nest.js
♋ Interactive Particle / Nest System With JavaScript and Canvas, no jQuery.
Stars: ✭ 3,966 (+1480.08%)
Mutual labels:  particles, canvas
Konfetti
Celebrate more with this lightweight confetti particle system 🎊
Stars: ✭ 2,278 (+807.57%)
Mutual labels:  particles, canvas
React Particles Webgl
🔆 A 2D/3D particle library built on React, Three.js and WebGL
Stars: ✭ 330 (+31.47%)
Mutual labels:  particles, canvas
Canvaskeyframes
最简单的序列帧动画canvas插件
Stars: ✭ 83 (-66.93%)
Mutual labels:  canvas, dom
Vue Canvas Nest
💫 A Vue.js background component for canvas-nest.
Stars: ✭ 136 (-45.82%)
Mutual labels:  particles, canvas
Black
World's fastest HTML5 2D game engine   🛸
Stars: ✭ 174 (-30.68%)
Mutual labels:  particles, canvas
Online Privacy Test Resource List
Privacy Online Test and Resource Compendium (POTARC) 🕵🏻
Stars: ✭ 185 (-26.29%)
Mutual labels:  canvas, dom
Tailwindcss Aspect Ratio
Aspect Ratio Plugin for tailwindcss framework
Stars: ✭ 243 (-3.19%)
Mutual labels:  plugin
Topology
A diagram (topology, UML) framework uses canvas and typescript. 一个轻量(100k左右)、功能丰富的绘图工具(微服务架构图、拓扑图、流程图、类图等UML图、脑图,动画、视频支持)。 【在线使用】:
Stars: ✭ 3,270 (+1202.79%)
Mutual labels:  canvas
Podlove Publisher
Podlove Podcast Publisher for WordPress
Stars: ✭ 241 (-3.98%)
Mutual labels:  plugin

Disintegrate

A small JS library to break DOM elements into animated Canvas particles.

For information about the technique itself, check out the related CSS-Tricks article.

Installation

You can either include html2canvas.js and Disintegrate.js directly into your project before using it or use npm install disintegrate. Make sure to call disintegrate.init() after Disintegrate (and html2canvas) is loaded for it to start applying its effects.

Demos

Built-in particle types

  • Particle - A rectangular particle that goes up in a sin wave, fading as it goes.
  • ExplodingParticle - A circular particle that goes in a random direction from its start point, getting smaller as it goes.

Creating custom effects

Adding a custom particle type

To add a custom particle type, simply create your particle to match the following format. For examples of custom particle creation, see the self-contained demo source.

/* These are the attributes that Disintegrate will update or call in a Particle */
var ExampleParticle = function() {
  // Used to determine the correct particle type based on the data-dis-particle-type
  this.name = "ExampleParticle";
  
  // Used to calculate the total percent finished of the animation
  // It should the equal to the longest time you want a particle to animate for
  this.animationDuration = <int>;

  // Updated only once when created
  this.startX = <int>;
  this.startY = <int>;
  this.rgbArray = [r, g, b, <a>];
  
  // Called until percent is greater than 1 (100%)
  this.draw = function(ctx, percent) { };
}

Then call disintegrate.addParticleType(ExampleParticle);.

Creating custom animations

In addition to the examples shown in the demos, you can use any CSS or JavaScript animations on the Disintegrate element and optionally container element. Animations have no effect on simultaneous Disintegrate elements.

Disintegrate HTML attributes

Applied on the Disintegrate element itself:

  • data-dis-type=<"contained" || "self-contained" || "simultaneous"> - Contained elements use an existing parent element as its Disintegrate container. Self-contained elements create a new div parent to be used as the Disintegrate container. Simultaneous elements don't make use of a container at all, but rather give the Particle full access to all of the element's color data at once to be processed as desired.
  • (optional) data-dis-particle-type="ExampleParticle" - This tells Disintegrate which particle type to use for a particular Disintegrate element.
  • (optional) data-dis-reduction-factor="35" - This reduces the number of particles created by the factor specified. The default is 35, which means only 1 of every 35th pixel in the element will be created. For large elements, this reduction factor should be higher for performance reasons.
  • (optional) data-dis-color="[r, g, b]" - This overrides Disintegrate's color detection on a per-pixel level and forces particles to be created solely with the color given in RGB format.
  • (optional) data-dis-ignore-colors="[r, g, b] <, ...[r, g, b]>" - This is a color or list of colors for Disintegrate to ignore, meaning that it won't create any particles with the given color.
  • (optional) data-dis-id="myDisId" - This specifies a Disintegrate ID for a particular element. It could be a Disintegrate element of a Disintegrate container's ID.
  • (optional) data-dis-container-id="myContainerId" - This is applicable on a Disintegrate element and specifies a Disintegrate container's ID to look for to be used as its container. It is for contained Disintegrate elements only.

Applied on the desired container:

  • (optional) data-dis-container - Specifies for this container to be used for any contained child Disintegrate elements unless a specific Disintegrate container is provided.
  • (optional) data-dis-id="myDisId" - This specifies a Disintegrate ID for a particular element. It could be a Disintegrate element of a Disintegrate container's ID.

Used in the demos for continuity but has no direct connection to Disintegrate:

  • (informal) data-dis-trigger-for="myDisId" - Used in the trigger demo to specify which self-contained Disintegrate element should fire when this element is clicked.

Disintegrate JavaScript events

These events are fired on the window.

  • disesLoaded - Fires when Disintegrate is done processing all of the Disintegrate elements on the page.
  • particlesReady - Fires when all of the html2canvas canvases have been created.

These events are fired on the Disintegrate element itself.

  • disOutOfBounds - Fires when a contained Disintegrate element goes completely outside of its container's bounds.
  • disInBounds - Fires when a contained Disintegrate element completely reenters its container's bounds after having gone out of its parent's bounds before.
  • disComplete - Fires when the animation duration for the Disintegrate element is complete (i.e. all particles are done animating).

Exposed API

After including disintegrate.js, the following are available to your code to use as needed:

  • disintegrate.init() - Start Disintegrate (necessary for Disintegrate to be able to load in a Node file without error) or reinitialize Disintegrate.
  • disintegrate.dises - An array of all Disintegrate objects.
  • disintegrate.createSimultaneousParticles(disObj) - A function to intiate the simultaneous particle creation for the given Disintegrate object.
  • disintegrate.getDisObj(element) - A function to get the Disintegrate object for a given element.
  • disintegrate.addParticleType(Function) - A function to add custom particle types that Disintegrate can recognize. It must at minimum meet Disintegrate's requirements for a particle.

Each disintegrate object also has a .kill() method that removes disintegrate object from the stored data and removes the relevant canvas from the page. This can be especially helpful when paired with the disComplete event:

disObj.elem.addEventListener("disComplete", () => disObj.kill() );

Known limitations

Most limitations on this approach stem from the use of html2canvas to render the DOM element on a Canvas. This includes, but is not limited to, nested transforms within the Disintegrate element and the lack of clip path support. For a more full list of limitations caused by html2canvas, look at its feature page).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].