CSSMathNegate: CSSMathNegate() 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 CSSMathNegate() constructor creates a new CSSMathNegate object which negates the value passed into it.
Syntax
js
new CSSMathNegate(arg)
Parameters
arg-
A number or
CSSNumericValuethat represents the value to negate.
Exceptions
None.
Examples
>Basic usage
The following code creates a CSSMathNegate object from a length, then logs the constructor name, value, and the object's serialization (from toString()).
js
const negated = new CSSMathNegate(CSS.px(10));
console.log(negated.constructor.name); // "CSSMathNegate"
console.log(negated.value); // CSSUnitValue {value: 10, unit: "px"}
console.log(negated.toString()); // "calc(-10px)"
Note that if a plain number is passed to arg, the value is rectified to a CSSUnitValue with unit "number":
js
const negatedNumber = new CSSMathNegate(4);
console.log(negatedNumber.value); // CSSUnitValue {value: 4, unit: "number"}
Specifications
| Specification |
|---|
| CSS Typed OM Level 1> # dom-cssmathnegate-cssmathnegate> |