1. Install & download the package.
# Yarn $ yarn add powerglitch # NPM $ npm i powerglitch
2. Import the PowerGlitch.
// ES6+
import { PowerGlitch } from 'powerglitch'
// ES5+
const PowerGlitch = require('powerglitch').PowerGlitch
// Browser
<script src="./dist/powerglitch.min.js"></script> 3. Add glitch elements to the page.
<imgsrc='1.png' class='glitch' /> <div class='glitch'> ... </div>
4. Initialize the PowerGlitch on the glitch element. That’s it.
PowerGlitch.glitch('.glitch') 5. Configure the glitch effect by overriding the default options and passing the options object as the second parameter to the glitch method.
PowerGlitch.glitch(
'.glitch',
{
/**
* Whether to avoid running the glitch effect on crawlers for SEO optimization.
*/ optimizeSeo: boolean,
/**
* Html to glitch. If not provided, will use the elements themselves.
* If provided, all elements should have an `innerHTML` property.
*/ html?: string,
/**
* Whether to create the 2 containers (one containing the other) necessary to create the glitch animation (defaults to true).
* @remarks
* The glitch effect relies on cloning the glitched element, and stacking them on top of the others inside 2 containers (one containing the other).
* The embedded container is called the layer container, it has grid display and stacks its children, which are the original element and its cloned versions.
* The top-level container replaces the original element (and the element is moved inside the layer container)
* This logic is necessary to ensure layout consistency before/after the glitch, and to create the actual glitch effect with CSS.
* In short, this maximizes compatibility for gitching about anything, but has to rearrange the DOM for that purpose.
*
* In some cases, it is better to handle this logic of two containers elsewhere than in PowerGlitch.
* For that, this flag should be false, which will make PowerGlitch.giltch(..) assume:
* - That the first argument to glitch(..) is the layer container itself
* - That the first child of the layer container is the element to glitch
* And will:
* - Clone the element to glitch the required amount of times, and add the clones at the same level than the element to glitch in the layer container
*/ createContainers: boolean,
/**
* Play mode. 'always', 'hover', 'click' and 'manual'
*/ playMode: PlayModes,
/**
* Whether to hide the glitch animation when it goes out of the bounding rectangle.
*/ hideOverflow: boolean,
/**
* Timing of the animation.
*/ timing: {
/**
* Duration of the animation loop in milliseconds.
*/ duration: number,
/**
* Number of times the animation should repeat. Set to `Infinity` to repeat forever.
*/ iterations: number,
/**
* Ease animation for all layers. Defauls to a sequential easing (no transition).
*/ easing?: string,
},
/**
* Specify if the animation should always glitch uniformly (if false) or if it should glitch at a given time.
* If start and end are set, the animation will glitch between those two times, and the peak glitch will be at the middle.
* glitchTimeSpan.end should be greater than glitchTimeSpan.start. Otherwise, the glitch will not happen.
*/ glitchTimeSpan: false | {
/**
* Start time of the glitch in percent, between 0 and 1.
*/ start: number,
/**
* End time of the glitch in percent, between 0 and 1.
*/ end: number,
},
/**
* Whether the base layer should shake. If not set to false, the base layer will shake in the given amplitude.
* The shake animation respects the glitch time span constraint, if set.
*/ shake: false | {
/**
* Number of steps to compute for each layer per second of animation.
*/ velocity: number,
/**
* Max X amplitude for the shake animation.
*/ amplitudeX: number,
/**
* Max Y amplitude for the shake animation.
*/ amplitudeY: number,
},
/**
* Slice layers are the base animation to give the glitch effect. They clip a part of the element and move it somewhere else.
* The slice animation respects the glitch time span constraint, if set.
*/ slice: {
/**
* Number of layers to generate.
*/ count: number,
/**
* Number of steps to compute for each layer per second of animation.
*/ velocity: number,
/**
* Minimum height in percent for a given slice, between 0 and 1.
*/ minHeight: number,
/**
* Maximum height in percent for a given slice, between 0 and 1.
*/ maxHeight: number,
/**
* Whether the hue should rotate for the given slice.
*/ hueRotate: boolean,
/**
* Apply custom CSS filters to glitch layers. Setting this will automatically disable hueRotate.
*/ cssFilters: string,
},
/**
* Pulse layer adds a pulsing effect to the glitch.
*/ pulse: false | {
/**
* Max scale
*/ scale: number,
},
},
) v2.5.0 (08/16/2024)
v2.4.0 (01/17/2024)
v2.3.5 (01/09/2024)
v2.3.3 (05/31/2024)
v2.3.2 (01/23/2023)
v2.3.0 (11/30/2022)
v2.2.0 (09/22/2022)
v2.1.0 (09/18/2022)
v2.0.2 (09/12/2022)
v2.0.1 (09/09/2022)
v2.0.0 (09/08/2022)
The post Glitch Images Using CSS Animations – PowerGlitch appeared first on CSS Script.
The Kobo Remote is small and lightweight, but large enough to be comfortable to hold.…
From left: Randi Weingarten, Steve Bannon, and Ralph Nader. | Image: Cath Virginia / The…
It’s another great month for new book releases, with a slew of fantastic stories from…
Pokémon Pokopia — currently the highest-rated Pokémon game of all time — is almost here.…
Will Powers, the public face of Crimson Desert in the west, has hit out at…
Next week's annual celebration of Super Mario will be marked by the return of three…
This website uses cookies.