Background Mask
backgroundMask lets particles punch through or blend with a masked background layer.
Examples
Static cover (legacy)
ts
backgroundMask: {
enable: true,
cover: {
color: {
value: "#0b1020",
},
opacity: 1,
},
}Dynamic draw callback (since 4.3.0)
ts
backgroundMask: {
enable: true,
cover: {
draw: (ctx) => {
const t = performance.now() * 0.001;
ctx.fillStyle = `hsl(${(t * 30) % 360}, 70%, 50%)`;
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
},
},
}External element (since 4.3.0)
ts
backgroundMask: {
enable: true,
cover: {
element: "#myVideo",
opacity: 0.8,
},
}Properties
| Property | Type | Description |
|---|---|---|
enable | boolean | Activates background masking |
composite | GlobalCompositeOperation | Canvas composite operation (default: "destination-out") |
cover | BackgroundMaskCover | Cover configuration |
cover (BackgroundMaskCover)
| Property | Type | Description |
|---|---|---|
color | string / OptionsColor | Cover color |
image | string | Cover image URL |
opacity | number | Cover alpha level (0..1, default: 1) |
element | string / HTMLCanvasElement / OffscreenCanvas / HTMLVideoElement / HTMLImageElement | External element or CSS selector auto-drawn each frame (since 4.3.0) |
draw | (context: BackgroundDrawContext, delta: IDelta) => void | Custom draw callback on main canvas context each frame (since 4.3.0) |
Layer order (since 4.3.0)
clear()— canvas pixel clearcover.elementauto-draw (if set)cover.drawcallback (if set)- Static cover (color/image) — fallback
- Global composite operation
When to use it
- Spotlight-like effects.
- Contrast-heavy hero sections.
- Layered interactions on dark backgrounds.
