大网数据广告活动
Web 标准与前端开发

CSSMathInvert: CSSMathInvert() constructor

· 52CE 我爱测

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

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。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。