CSSRotate: CSSRotate() 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 CSSRotate() constructor creates a new CSSRotate object representing the rotate() value of the individual transform property in CSS.
This can be specified as either a 2D rotation by a particular angle, or as a 3D rotation by an angle around a particular axis.
Syntax
new CSSRotate(angle)
new CSSRotate(x, y, z, angle)
Parameters
angle-
A value for the angle of rotation of the
CSSRotateobject to be constructed. This must be aCSSNumericValue. xOptional-
A number or
CSSNumericValuevalue indicating the x-coordinate of the rotation axis vector of theCSSRotateobject to be constructed. Only used, and required, when constructing a 3D rotation; the 2-argument form implies a rotation axis of(0, 0, 1)(the z-axis). yOptional-
A number or
CSSNumericValuevalue indicating the y-coordinate of the rotation axis vector of theCSSRotateobject to be constructed. Only used, and required, when constructing a 3D rotation. zOptional-
A number or
CSSNumericValuevalue indicating the z-coordinate of the rotation axis vector of theCSSRotateobject to be constructed. Only used, and required, when constructing a 3D rotation.
Exceptions
Examples
>Constructing a 2D rotation
The 2-argument form takes only an angle, and implies a rotation around the z-axis (equivalent to rotate3d(0, 0, 1, angle)):
const rotate2D = new CSSRotate(CSS.deg(45));
console.log(rotate2D.is2D); // true
console.log(rotate2D.toString()); // "rotate(45deg)"
Constructing a 3D rotation
The 4-argument form takes the rotation axis coordinates followed by the angle:
const rotate3D = new CSSRotate(1, 1, 0, CSS.deg(45));
console.log(rotate3D.is2D); // false
console.log(rotate3D.toString()); // "rotate3d(1, 1, 0,45deg)"
Handling an invalid angle
try {
const rotate = new CSSRotate(CSS.px(45));
} catch (e) {
console.log(e); // TypeError: px is not an angle
}
Specifications
| Specification |
|---|
| CSS Typed OM Level 1> # dom-cssrotate-cssrotate> |
| CSS Typed OM Level 1> # dom-cssrotate-cssrotate-x-y-z-angle> |