Resources

Advanced

More complex behavior: canvas, SVG and anything heavier than the everyday attachments and components.

[ Bg Dust - Attachment ]

A moving, grainy light field behind an element, drawn on the GPU. Soft glows drift, form and dissolve, a fine sparkle flows through them, and the pointer pushes them along and lights the field under it. It follows the site's light and dark theme, and it can also change theme as the page scrolls. It only runs while the element is on screen, and with reduced motion it draws one still frame. A site uses one instance: on a section, or on <body> with fixed, where sections should have no background of their own. Every option is optional, and the groups (lobes, ripple, turbulence, mouse, crease, vignette) take only the values you set.

Available options:

  • fixed A boolean. Covers the whole screen and follows it, instead of covering the element. Meant for <body>. Defaults to false.
  • colors { dark, light }, each { base, highlight }: the field and the glow that drifts across it, as any CSS color. Defaults to navy for dark and white with a blue glow for light.
  • theme follow | dark | light. follow matches the site's theme (the data-theme on <html>), or pin it to one. Defaults to follow.
  • sections A boolean. With follow, changes theme as the page scrolls, to match each element with data-bg-theme="light" or "dark". data-bg-theme-start (0-1, default 0.5) sets how far up the screen the element must be. Defaults to false.
  • motionSpeed A number, the pace of everything that moves. 0 freezes it. Defaults to 3.5.
  • fadeIn A number, seconds the glow takes to fade in on load. Defaults to 3.
  • lobes { count, drift, radius, radiusVariance, formMin }. How many glows (1-4, default 3), how far each wanders (0.46), their average size (0.3), how much that varies (0.14), and the lowest brightness one dips to (0.12, and 0 lets it vanish).
  • ripple { enabled, centerX, centerY, spacing, shift, cycles }. Stationary rings, centered above the top edge, that cut the glow into bands. Defaults are true, 0, 1.4, 0.18, 0.85 and 1.
  • turbulence { speed, scale, intensity, curl, curlScale }. The fine sparkle: how fast it drifts (0.0075), how fine it is (520, higher is finer), how bright (0.08), and how much it wobbles (0.5, scale 3.5).
  • mouse { radius, glowRadius, push, glowBoost, positionSmoothing, influenceSmoothing, velocityReference, velocityAttack, velocityRelease, sparkle, sparkleRadius, sparklePush, sparkleTrail, sparkleTrailLength, sparkleEdgeNoise, sparkleSwap, sparkleDirectionSmoothing }. How the pointer pushes the glows and lights the field. sparkle: true lets it push the sparkle as well, with a trail. The defaults are the tuned ones, so start from push, glowBoost and sparkle.
  • crease { angle, offset, width, strength }. A soft diagonal shadow. Defaults are -20, 0.08, 0.24 and 0.12.
  • vignette { start, end, strength }. Darkens the edges. Defaults are 0.15, 0.95 and 0.55.
  • grain A number, the film grain from 0 up. Defaults to 0.035.

Defaults

Follows the site theme: switch the theme in the footer to see both palettes.

A mock section

Content sits in front

Move the mouse over this frame. The effect is drawn behind everything in the section.

Accent colors, with sparkle

Custom colors in the accent, no ripple, and mouse.sparkle so the pointer pushes the fine grain too.

A mock section

Content sits in front

Move the mouse over this frame. The effect is drawn behind everything in the section.

[ Bg Grid - Attachment ]

Draws a grid of lines behind an element. Squares near the pointer light up and fade away, and every so often the grid lights up by itself so a visitor without a mouse still sees it. It is a transparent canvas behind the element's content, so the element's own background shows through, and it only runs while something is animating and the element is on screen. It does nothing when motion is reduced. Put it on a section to give just that section a grid, or on <body> with fixed for the whole site, where sections should have no background of their own.

Available options:

  • cellSize A number, the width and height of each square in px. Defaults to 48.
  • color A string, any CSS color for the lines, including var(--color-border). Defaults to var(--color-border).
  • lineWidth A number, the line width in px. Defaults to 1.
  • fade A number, seconds a square takes to fade away. Defaults to 0.85.
  • spread A number from 0 to 1, the chance that each square touching the one under the pointer lights up too. Defaults to 0.5.
  • ambient A number, milliseconds between the grid lighting up by itself. 0 turns it off. Defaults to 7500.
  • fixed A boolean. Covers the whole screen and follows it, instead of covering the element. Meant for <body>. Defaults to false.
  • show A boolean, or { enter, exit, stagger }. Holds the whole grid on while the element is mostly on screen, then fades it out. enter and exit are how it sweeps: stack-top, stack-bottom, stack-left, stack-right, ripple-out, ripple-in, random, diag-tl, diag-tr, diag-br or diag-bl (default stack-top), and stagger is milliseconds between squares (default 50).
  • disableOn A selector for elements inside that stop the pointer from lighting squares while it is over them, such as buttons.
  • hideOn A selector for elements inside that hide the grid completely while the pointer is over them.

Follows the pointer

The defaults, with disableOn: '.demo-button' so the button's own area stays dark.

A mock section

Content sits in front

Move the mouse over this frame. The effect is drawn behind everything in the section.

Shown while in view

show with ripple-out in and out, cellSize: 32. The whole grid ripples in from the center when the second section scrolls into view and out again as it leaves. The grid covers the whole mock site, and trigger: '.demo-trigger' picks the section that turns it on.

Section one

Scroll down

Section two

The effect is on here

It turns on while this section is in view and off again when it leaves.

Section three

No effect here

[ Bg Waves - Attachment ]

A field of particles that ripples like water, seen from above and behind, drawn on the GPU. With follow, particles near the pointer light up to full strength. The color follows the site's theme when it is a CSS variable. It only runs while the element is on screen, and with reduced motion it draws one still frame. Sizes are in the field's own units, not px: width and depth set how far it spreads and gap how tightly it is filled, so a smaller gap draws many more particles.

Available options:

  • fixed A boolean. Covers the whole screen and follows it, instead of covering the element. Meant for <body>. Defaults to false.
  • width A number, how far the field spreads from side to side, in the field's own units. Defaults to 40.
  • depth A number, how far it spreads front to back, in the same units. Defaults to 25.
  • gap A number, the space between particles in the same units. Smaller draws more of them. Defaults to 0.5.
  • color A string, any CSS color, including var(--color-accent). Defaults to var(--color-text).
  • opacity A number from 0 to 1, how solid the particles are. Below 1, follow can light them up. Defaults to 1.
  • speed A number, how fast the waves move. Defaults to 0.01.
  • follow A number, how far from the pointer particles light up to full strength, in the field's own units. 0 turns it off, and it needs an opacity below 1 to show. Defaults to 0.
  • fadeTop A number, how much of the top edge fades out, as a percent of the height. 0 leaves it hard. Defaults to 0.
  • camera { height, distance, fov }, where the camera looks down from and how wide it sees. Defaults are 6, 5 and 75.

Defaults

The theme's text color, with a faded top edge.

A mock section

Content sits in front

Move the mouse over this frame. The effect is drawn behind everything in the section.

Follows the pointer

Accent color, opacity: 0.5 and follow: 25, so particles near the pointer light up. A smaller gap makes it denser.

A mock section

Content sits in front

Move the mouse over this frame. The effect is drawn behind everything in the section.

[ Cursor Fluid - Attachment ]

A faint, liquid ribbon that follows the mouse. The pointer stirs a small fluid simulation on the GPU and leaves a thin trail that bends along and fades quickly. By default the light splits into colored fringes, like glass; mode: 'ink' makes it a soft tint of one color instead. It sits behind the element's content, so it shows on the open background around text and images. In ink mode it follows the site's theme for its color. It only runs while the pointer is moving over an element on screen. It does nothing when motion is reduced or without a mouse. Put it on a section, or on <body> with fixed for the whole site, where sections should have no background of their own.

Available options:

  • fixed A boolean. Covers the whole screen and follows it, instead of covering the element. Meant for <body>. Defaults to false.
  • color Any CSS color for the fluid, including var(--color-accent). Defaults to the accent color.
  • opacity A number from 0 to 1, how solid the fluid is where it is thickest. Defaults to 0.5.
  • size A number, the size of the splash under the pointer as a fraction of the screen's shorter side. Defaults to 0.03.
  • force A number, how hard the pointer pushes the fluid along. Defaults to 2000.
  • swirl A number, how strongly the fluid curls into eddies. 0 leaves it smooth. Defaults to 4.
  • fade A number from 0 to 1, how much color is left after one second. Lower disappears sooner. Defaults to 0.03.
  • drag A number from 0 to 1, how much speed is left after one second. Lower stops sooner. Defaults to 0.05.

Defaults

Move the mouse across the frame, and over the empty space around the text.

A mock section

Content sits in front

Move the mouse over this frame. The effect is drawn behind everything in the section.

Ink

mode: 'ink' in the accent color, with a larger size, more swirl and a slower fade, so it billows like ink in water.

A mock section

Content sits in front

Move the mouse over this frame. The effect is drawn behind everything in the section.

[ Dots Fill - Attachment ]

Goes on an <svg>, or on an <img>. On an <svg> it turns the fill of every shape inside into a grid of dots that the pointer pushes around: a dot is drawn wherever a grid point lands inside a shape, and the shapes are hidden until the attachment is removed. Use rect, circle, ellipse, path and polygon without a transform. An <img> keeps its shapes out of reach, so it is drawn to a canvas instead and every grid point on a solid pixel gets a dot. That works for an SVG file and for any picture with transparency, such as a PNG or WebP cut-out, as long as it comes from your own site or allows cross-origin reads. On an <img> the sizes are in px and the dots are redone when it resizes. The dots only move while it is on screen, and stay still when motion is reduced.

Available options:

  • size A number, the radius of each dot in the SVG's own units. Defaults to 1.
  • gap A number, the space between dot centers in the same units. Defaults to 16.
  • restore A number from 0 to 1, how quickly the pointer's speed fades once it stops. Higher stops the push sooner. Defaults to 0.04.
  • sensitivity A number from 0 to 1, how long dots keep moving after a push. Closer to 1 springs back more slowly. Defaults to 0.95.
  • distance A number, how far from the pointer dots react, in the SVG's own units. Defaults to 50.
  • strength A number, how hard the pointer pushes dots away. Defaults to 10.
  • color A string, any CSS color, including var(--color-accent). Defaults to the SVG's own text color.
  • illuminate A boolean. Dots dim away from the pointer, so the ones near it light up. Defaults to false.
  • grow A number, how much dots swell near the pointer as a multiple of their size. 0 keeps them the same size. Defaults to 0.

[ Grid Flow Img - Attachment ]

Goes on an <img>. The picture is cut into blocks that the mouse drags along as it moves, with a color split that follows the speed of the move and fades once it stops. A canvas is laid over the image and draws the same picture with a small WebGL shader, so no library is loaded. Size and shape come from your own CSS on the image, and the canvas takes its position and rounded corners. It does nothing without a mouse or with reduced motion, and the image is left as it is. The picture must be from your own site or allow cross-origin reads.

Available options:

  • ease A number from 0 to 1, how quickly the effect follows the pointer. Lower trails further behind. Defaults to 0.05.
  • range A number from 0 to 1, how far from the pointer the effect reaches, as a share of the image. Defaults to 0.3.
  • grid A number, how many blocks the image is cut into along each side. Fewer is chunkier. Defaults to 32.
  • intensity A number, how strong the color split is while the pointer moves. Defaults to 1.
  • fit cover | contain | stretch. How the picture sits in the image's box, like object-fit. Defaults to cover.
  • greyscale A boolean. Draws in black and white until the pointer is over it. Defaults to true.
A mountain range under clouds
A ridge above a river valley Smoke rising from a canyon

[ Image Lens - Attachment ]

A glass lens that follows the mouse over a picture, a port of the hero lens on stripesessions.com. The picture is read into a WebGL texture and a small shader bends it at the edge of a circle, enlarges the middle, splits the colors, blurs and adds a highlight. Because it is drawn from the picture's own pixels and not the page behind it, it works in every browser, Safari included, which backdrop-filter with an SVG filter does not. Put it on an <img>. It follows object-fit and object-position, appears while the mouse is over the picture, shrinks a little when pressed, and follows the picture's rounded corners. It needs a picture from this site, or one served with CORS headers. It does nothing without a mouse, and with reduced motion the lens follows without easing. Each picture uses one WebGL context.

Available options:

  • radius A number, the radius of the lens in px. Defaults to 60.
  • refraction A number, how strongly the rim bends the picture. Defaults to 1.
  • bevel A number from 0 to 1, how much of the radius is the bent rim. Defaults to 0.4.
  • magnify A number, how much the middle is enlarged. Defaults to 0.12.
  • dispersion A number, how far the colors split apart at the rim. Defaults to 0.24.
  • blur A number, the blur through the glass in px. Defaults to 4.2.
  • tint A number from 0 to 1, how much white is mixed in, strongest on the right. Defaults to 0.45.
  • highlight A number from 0 to 1, how bright the light on the top left of the rim is. Defaults to 0.7.

Clear

Less blur and tint, so the picture shows through almost untouched. Move the mouse over it.

A sample

Large and bent

A bigger radius with stronger refraction and magnify, and only a little blur and tint, so the picture bends without clouding.

A sample

[ Text Flies - Attachment ]

Turns text into a swarm of tiny dots that drift inside the letters, a port of the Flies material from Blotter.js. The text is drawn on a canvas over the element and shown on the GPU, and the real text stays in place, invisible but selectable and readable by screen readers. It takes the element's color, font, size and line breaks. It only runs while the element is on screen, redraws when the size, fonts or theme change, and does nothing when motion is reduced. Each element uses one WebGL context, so keep it to a few headings per page.

Available options:

  • cell A number, the size of the cell each fly roams in, as a fraction of the font size. Smaller means more, finer dots. Defaults to 0.025.
  • radius A number from 0 to 1, how big each dot is within its cell. Defaults to 0.75.
  • grow A number, how far the dots may roam past the edges of the letters, in cells. Without it the words look narrower than the real text, since a dot needs its whole cell inside a letter. 0 keeps them inside. Defaults to 0.5.
  • speed A number, how fast the dots drift. Defaults to 1.
  • dodge A boolean. Dots near the mouse scatter away from it, leaving a hole that follows the pointer. Defaults to false.
  • dodgeSpread A number, how far the scatter reaches, as a fraction of the element's height. Defaults to 0.25.

Defaults

The flies

Dodge

dodge with finer dots (cell). Move the mouse over the text.

Scatter