atan2()
Baseline 2023Newly available
Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
CSS 函数 atan2()
为三角函数,返回介于 -infinity
和 infinity
之间的两值的反正切值。此函数接受两个参数,返回表示介于 -180deg
和 180deg
之间的
的弧度数。
语法
css
/* 两个 值 */
transform: rotate(atan2(3, 2));
/* 两个 值 */
transform: rotate(atan2(1rem, -0.5rem));
/* 两个 值 */
transform: rotate(atan2(20%, -30%));
/* 其他值 */
transform: rotate(atan2(pi, 45));
transform: rotate(atan2(e, 30));
参数
返回值
形式语法
示例
旋转元素
由于 atan2()
函数返回
,故可用于旋转(rotate
)元素。
HTML
html
CSS
css
div.box {
width: 100px;
height: 100px;
background: linear-gradient(orange, red);
}
div.box-1 {
transform: rotate(atan2(3, 2));
}
div.box-2 {
transform: rotate(atan2(3%, -2%));
}
div.box-3 {
transform: rotate(atan2(-1, 0.5));
}
div.box-4 {
transform: rotate(atan2(1, 0.5));
}
div.box-5 {
transform: rotate(atan2(1rem, -0.5rem));
}
结果
规范
Specification |
---|
CSS Values and Units Module Level 4 # trig-funcs |