Decoration behind a hero that carries no information, such as drifting hexagons or color fields.
<div class="ambient-demo" id="am-hex">
<div class="cap-ambient" data-cap="ambient" data-variant="hex-field" aria-hidden="true"></div>
<p class="ambient-demo-words">Editing by scientists, for scientists.</p>
</div>
Copy
Installation
HTML and CSS React
// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/ambient.css";
import { enhance } from "capsomer/behavior/ambient";
enhance();Copy
import "capsomer/tokens.css";
import "capsomer/ambient.css";
import { Ambient } from "capsomer/react/ambient";Copy
Usage
<div class="hero"> <!-- position: relative; the words above at z-index 1 -->
<div class="cap-ambient" data-cap="ambient" data-variant="hex-field" aria-hidden="true"></div>
<div class="cap-ambient" data-cap="ambient" data-variant="blobs" aria-hidden="true"><span></span><span></span><span></span><span></span></div>
</div>
<div class="cap-ambient" data-cap="ambient" data-variant="equalizer" aria-hidden="true"><span></span> ... 28 spans</div>Copy
Examples
Blobs
<div class="ambient-demo" id="am-blobs">
<div class="cap-ambient" data-cap="ambient" data-variant="blobs" aria-hidden="true"><span></span><span></span><span></span><span></span></div>
<p class="ambient-demo-words">Field notes, every week.</p>
</div>
Copy
Equalizer
<div class="cap-ambient" data-cap="ambient" data-variant="equalizer" aria-hidden="true" id="am-eq"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></div>
Copy
API reference
Ambient Prop Type Required Does variant"hex-field" | "blobs" | "equalizer"Yes hideOnPhonebooleanThe equalizer only: left out under 48rem (data-hide="phone"). countnumberHexagons on a wide screen and on a phone (under 48rem). The source's 24 and 12. phoneCountnumberrandom() => numberA random source, for a test that wants the same field twice.
Functions Function Signature Does drawHexes(field: HTMLElement, options?: HexOptions): HTMLElement[]The source's ranges: size 45 to 89px, top 0 to 90%, left 0 to 95%, 25 to 44s a cycle, started up to 29s in. pauseOffscreen(layer: HTMLElement): () => voidMarks the layer data-paused while it is off screen. enhance(root?: ParentNode, options?: HexOptions): () => void
CSS variables Variable Default --cvar(--cap-ambient-1)--cap-ambient-1var(--primary)--cap-ambient-2var(--accent)--cap-ambient-3var(--info)--cap-ambient-4var(--surface)--cap-ambient-flip-1--cap-ambient-height4rem--cap-ambient-strengthvar(--opacity-muted)--cap-ambient-strength-darkvar(--opacity-faint)--cap-ambient-width13rem--d30s--dx26px--dy20px--h52%--k1.12--l-4s--o0.55--s26rem--x2%--y-40%
Parts and data attributes Class Is .cap-ambientthe root
Attribute Values data-hidephonedata-pausedpresent or absent data-variantblobs equalizer hex-field
Accessibility
Nothing to operate.
Decorative only; the hero's words must reach their contrast over the layer at its brightest. germomics tuned its blob positions by eye to keep the lede at 4.5:1 in both themes; a site that moves them checks again.