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.
Installation
pnpm dlx shadcn@latest add @breeze/chainsUsage
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
| Prop | Type | Default | Description |
|---|---|---|---|
color | string | "var(--foreground)" | Iron colour, any CSS colour or var() |
rustColor | string | "#c46830" | Rust colour; the shadowed rust is a darker shade of it |
rust | number | 1 | How much rust. 0 for clean iron, 2 for nearly all of it |
count | number | 0 | How many swags hang across the top (about half on narrow screens). 0 picks one per ~240px of width |
size | number | 52 | Link length in CSS px. Everything else scales with it |
pixelSize | number | 2 | Size of one dither pixel in CSS px |
slack | number | 1 | How deep the swags sag |
strands | number | 1 | How long the hanging strands are. 0 for swags only |
depth | boolean | true | Add a dimmer layer of longer chains behind |
clearance | number | 0.5 | Share of the width, 0 to 0.9, kept clear in the middle |
wind | number | 1 | Wind strength. 0 is still air |
interactive | boolean | true | Push the chains with the pointer over the canvas |
radius | number | 60 | How far the pointer reaches, in CSS px |
seed | number | 7 | Layout seed. Change it to reroll the arrangement |
strength | number | 1 | Opacity multiplier, 0 to 1 |
fps | number | 60 | Frame 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
<Chains
rust={0}
color="#94a3b8"
count={4}
size={64}
clearance={0}
className="absolute inset-0 h-full w-full"
/>Fine and still
<Chains
size={30}
pixelSize={1}
count={9}
wind={0}
strands={1.6}
className="absolute inset-0 h-full w-full"
/>