CSSMathInvert: CSSMathInvert() constructor

Note: This feature is available in Web Workers.

The CSSMathInvert() constructor creates a new CSSMathInvert object which represents the inverse (reciprocal) of a CSSNumericValue.

Syntax

js
new CSSMathInvert(arg)

Parameters

arg

A number or CSSNumericValue that represents the value to invert.

Exceptions

None.

Examples

undefined

Basic usage

The following code creates a CSSMathInvert object from a percentage, then logs the constructor name, value, and the object's serialization (from toString()).

js
const inverted = new CSSMathInvert(CSS.percent(4));

console.log(inverted.constructor.name); // "CSSMathInvert"
console.log(inverted.value); // CSSUnitValue {value: 4, unit: "percent"}
console.log(inverted.toString()); // "calc(1 / 4%)"

Note that if a plain number is passed to arg, the value is rectified to a CSSUnitValue with unit "number":

js
const invertedNumber = new CSSMathInvert(4);

console.log(invertedNumber.value); // CSSUnitValue {value: 4, unit: "number"}

Specifications