pixelCeil

Commons
stable

Ceil a sub-pixel value to the nearest physical pixel boundary using `devicePixelRatio`. Prevents layout rounding errors in high-DPI positioning calculations.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

val
required
number
A CSS pixel value (fractional or whole). Multiplied by `devicePixelRatio`, ceiled, then divided back to get the nearest physical-pixel boundary.

API

Return value

The value returned by this util.

The input ceiled to the nearest physical pixel grid line in CSS pixel units.

Usage

Examples

Ready-to-paste usage snippets.

Ceil to physical pixel (2x display)

typescript