CSSMathInvert: CSSMathInvert() constructor
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Want more browser support for this feature? Tell us why.
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
CSSNumericValuethat represents the value to invert.
Exceptions
None.
Examples
>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
| Specification |
|---|
| CSS Typed OM Level 1> # dom-cssmathinvert-cssmathinvert> |