Note: This feature is available in Web Workers.
The toSum() method of the CSSNumericValue interface converts the object's value to a CSSMathSum of CSSUnitValues using only the specified units, if possible. If called with no units, it simplifies the value into a minimal sum of CSSUnitValues instead.
toSum()
toSum(unit1)
toSum(unit1, unit2)
toSum(unit1, unit2, /* …, */ unitN)unit1, …, unitN OptionalThe units to convert to.
A CSSMathSum.
SyntaxError DOMExceptionThrown if any of unit1, …, unitN is not a valid unit identifier.
TypeErrorThrown if:
CSSUnitValues — for example, because one of its terms has a compound unit (such as px * s) that can't be represented by a single CSSUnitValue.let v = CSS.px("23").add(CSS.percent("4")).add(CSS.cm("3")).add(CSS.in("9"));
v.toString(); // => "calc(23px + 4% + 3cm + 9in)"
v.toSum("px", "percent").toString(); // => "calc(1000.39px + 4%)"