Browser Helpers
Utility functions for working with browser operations.
Functions
Section titled “Functions”| Function | Description |
|---|---|
decodeImage | Loads an image and waits until it is decoded, so it can be painted without a flash or a decoding pause (e.g. |
loadFont | Loads a font and registers it in `document.fonts`, so CSS and canvas can use `family` right away. |
matchesMedia | Whether the document currently matches a CSS media query. |
observeIntersection | Calls `callback` each time `element` enters or leaves the viewport (or `options.root`), with an `IntersectionObserver`… |
observeResize | Calls `callback` each time the size of `element` changes, with a `ResizeObserver` dedicated to it. |
prefersReducedMotion | Whether the user asked the system to reduce motion (`prefers-reduced-motion: reduce`). |
preloadImages | Loads and decodes several images with decodeImage, a few at a time, with `mapSettled` from `helpers4/array`. |
watchMedia | Calls `listener` each time a CSS media query starts or stops matching. |
whenIdle | Runs `callback` when the browser is idle, with `requestIdleCallback`, for work that can wait (prefetching, analytics, w… |
