Liquid Gradient
Interactive liquid atmosphere rendered with vanilla WebGL (no Three.js). Colors follow VD3 UI primary, neutral, and background tokens and update live with light/dark theme changes. Move the pointer over the demo to ripple the surface.
Live demo
Use the site theme switcher to flip light/dark and primary — the gradient rebinds automatically. Drag the knobs to override --vd-liquid-* on this host.
Markup
API reference
Wiring
import { ref } from 'vue';
import { useLiquidGradient } from "@vanduo-oss/vd3";
const root = ref<HTMLElement | null>(null);
useLiquidGradient(root);
// Scans .vd-liquid-gradient hosts; starts when .vd-liquid-gradient-active
// (or data-vd-liquid-active) is present. Theme + --vd-liquid-* sync automatically.Factory (framework-agnostic)
Classes & attributes
| Class / attribute | Applies to | Effect |
|---|---|---|
.vd-liquid-gradient | host | Required host. Holds --vd-liquid-* knobs; decorative (pointer-events: none). |
.vd-liquid-gradient-canvas | child | WebGL canvas. Auto-created by useLiquidGradient if missing. |
.vd-liquid-gradient-active | host | Visible + running. Without it the engine stays stopped. |
data-vd-liquid-active | host | Alternate active flag (any value except "false"). |
.vd-liquid-gradient-fixed | host | position: fixed; inset: 0 — full-viewport atmosphere. |
.vd-liquid-gradient-fill | host | position: absolute; inset: 0 — fill a positioned parent. |
Customization tokens
| Token | Default | Role |
|---|---|---|
--vd-liquid-speed | 1.15 | Orbit / animation speed multiplier |
--vd-liquid-intensity | 1.35 | Overall color intensity |
--vd-liquid-grain | 0.05 | Film-grain overlay strength |
--vd-liquid-distort | 0.48 | Pointer UV distortion strength |
--vd-liquid-gradient-size | 0.48 | Radial blob radius |
--vd-liquid-primary-weight | 0.85 | Primary color contribution |
--vd-liquid-neutral-weight | 1.15 | Neutral color contribution |
--vd-liquid-alpha | 1 | Fragment output alpha |
Theme colors come from --vd-color-primary-rgb / --vd-color-primary, --vd-neutral-2/6/8, and --vd-bg-primary, mixed differently for data-theme="light" vs dark.
Accessibility
- Mark the host
aria-hidden="true"— it is decorative. prefers-reduced-motion: reducedraws a static frame (speed/distort = 0, no pointer trails).- If WebGL is unavailable, the factory returns
nulland the composable no-ops without throwing. - Host uses
pointer-events: noneso UI above remains clickable; pointer sampling is window-level while active.
Inspired by the MIT-licensed CodePen “Interactive Liquid Gradient using Three.js” by Cameron Knight. VD3 UI ships a vanilla WebGL reimplementation bound to theme tokens and --vd-liquid-* knobs — no Three.js CDN.