CSS Typed Object Model API
The CSSMathInvert() constructor creates a new CSSMathInvert object which represents the inverse (reciprocal) of a CSSNumericValue.
Syntax
new CSSMathInvert(arg)
Parameters
arg- : A number or CSSNumericValue that 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 CSSStyleValue/toString).
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, it's converted to a CSSUnitValue whose unit is "number":
const invertedNumber = new CSSMathInvert(4);
console.log(invertedNumber.value); // CSSUnitValue {value: 4, unit: "number"}
Specifications
Browser compatibility
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
