Falling snow on a canvas, for a front page with a winter feel. Each flake has its own size, speed and sway, over a slow global wind. The snow is decorative only: it doesn't react to the pointer or clicks, and the rest of the look is fixed on purpose.
Install
Requires @intility/bifrost-experimental, installed and set up. Then import the component:
import SnowBackground from "@intility/bifrost-experimental/SnowBackground";Usage
Render it as the first child of the container that wraps the whole front page, and give that container position: relative and isolation: isolate:
const FrontPage = () => (
<div className="page">
<SnowBackground />
{/* page content */}
</div>
);.page {
position: relative;
isolation: isolate;
}The snow covers the top 35% of the viewport height, whatever the height of the container, so the background looks the same on every front page. On a short viewport it still covers at least 240px. If the container is shorter than that, it covers the whole container. Content that scrolls below the fold doesn't stretch it.
The page should have one plain --bfc-base-1 background all the way down. Anything between the page and the snow, like a section with its own background color, hides it.
The snow is white in dark mode, and a pale steel blue in light mode, where pure white would vanish into the page.
Inside a Box
By default the snow covers the top 35% of the viewport height and fades out, which suits a whole page. To use the background in a smaller container, like a Box or a card, set fill. The snow then covers the whole container. Give the container position: relative and isolation: isolate, as above.
The snow still fades in over the top and out over the bottom edge of the container, so no flake pops in or out of view. overflow: clip keeps the snow inside a Box with large rounded corners.
Custom height
height sets how much of the container the snow covers, in percent from 0 to 100. It overrides the default height and fill; height={100} is the same as fill. Values outside the range are clamped to it.
The prop is optional. Without it, the snow covers the top 35% of the viewport height, at least 240px, and fill covers the whole container.
The snow still fades in over the top and out over the bottom edge of the band, so the edge of the snow cannot be seen.
Good to know
- If a control sits closer to the screen edge than the page padding, give the page container
overflow-x: clip, so its backdrop doesn't cause sideways scrolling.
Accessibility
- When reduced motion is turned on, the snow stops after one still frame. This applies at once, without a reload.
- There is no pause control. WCAG 2.2.2 (Pause, Stop, Hide) asks for one for animation that runs longer than 5 seconds, so an accessibility audit may flag it.
- In forced colors mode, such as Windows high contrast, no snow is drawn.