Chains

Heavy iron chains hung across the top of a section, simulated with Verlet physics and drawn in ordered dither, with rust, a light wind and a pointer that pushes them aside.

Props
Iron
theme
Rust
#c46830
Rust amount1.00
Swags (0 = auto)0
Link size52
Pixel size2
Slack1.00
Strands1.00
Clearance0.50
Wind1.0
Push radius60
Seed7
Strength1.00

Installation

pnpm dlx shadcn@latest add @breeze/chains

Usage

import { Chains } from "@/components/breeze/chains"

The chains hang from the top edge of the canvas, so put it at the top of a hero. The canvas is transparent and fills its box: put it in a positioned parent that has a size, as below, or give it a height of its own. In a box with no height it's 0 tall.

<section className="relative isolate h-[560px] overflow-hidden">
  <Chains className="absolute inset-0 -z-10 h-full w-full" />
  <div className="relative pt-40 text-center">{/* headline */}</div>
</section>

It reads the pointer on the window, so links and buttons on top keep working, and moving anywhere over the canvas pushes the chains aside.

It looks at the background it sits on and shades to match: on a dark page, bright glints over a faint body; on a light page, solid dark iron with pale glints, and the back layer fades toward the page. It switches when the theme does.

Layout

Every arrangement comes from seed, so the same seed always hangs the same way. Pins sit along the top at slightly different heights, with a swag of its own slack between each pair, strands hanging from the pins and the middle of the outer swags, and a dimmer back layer of longer chains crossing behind (depth).

clearance keeps the middle of the box clear for a headline: only shallow chain crosses that column, and the long strands hang beside it. Set it to 0 to hang chain anywhere. Below 760px wide the chains switch to about half as many swags and a wider clear column.

Everything scales with size, the link length, so a bigger link gives the same arrangement at a bigger scale. pixelSize only changes how chunky the dither is.

How it moves

A light wind sways the chains (wind), and the pointer pushes links within radius aside. The physics always runs at 60 steps a second, whatever fps caps the drawing at. With wind={0} the chains come to rest and the animation stops until the pointer moves again, so a still background costs nothing. It pauses off-screen and shows the settled chains with reduced motion.

Props

PropTypeDefaultDescription
colorstring"var(--foreground)"Iron colour, any CSS colour or var()
rustColorstring"#c46830"Rust colour; the shadowed rust is a darker shade of it
rustnumber1How much rust. 0 for clean iron, 2 for nearly all of it
countnumber0How many swags hang across the top (about half on narrow screens). 0 picks one per ~240px of width
sizenumber52Link length in CSS px. Everything else scales with it
pixelSizenumber2Size of one dither pixel in CSS px
slacknumber1How deep the swags sag
strandsnumber1How long the hanging strands are. 0 for swags only
depthbooleantrueAdd a dimmer layer of longer chains behind
clearancenumber0.5Share of the width, 0 to 0.9, kept clear in the middle
windnumber1Wind strength. 0 is still air
interactivebooleantruePush the chains with the pointer over the canvas
radiusnumber60How far the pointer reaches, in CSS px
seednumber7Layout seed. Change it to reroll the arrangement
strengthnumber1Opacity multiplier, 0 to 1
fpsnumber60Frame rate cap

Colours, rust, wind, interactive, radius, strength, pixelSize and fps update live. The layout props (seed, count, size, slack, strands, depth, clearance) rehang the chains, as does resizing the box. The iron follows your theme through var(--foreground) and repaints when the theme changes.

Any other canvas prop, like id, style or data-*, is passed to the canvas. It's aria-hidden unless you override it.

Examples

Clean steel

Fine and still