HTML DOM Style perspectiveOrigin 属性
htmldomweb developmentfront end technology更新于 2024/5/23 16:44:17
HTML DOM Style perspectiveOrigin 属性返回并修改 3D 元素在 HTML 文档中 x 轴和 y 轴的位置。
语法
以下是语法 −
1. 返回 perspectiveOrigin
object.perspectiveOrigin
2. 修改 perspectiveOrigin
object.perspectiveOrigin = “value”
此处,值可以为 -
| 值 | 说明 |
|---|---|
| initial | 将此属性值设置为其默认值。 |
| inherit | 从其父元素继承此属性值。 |
| x-axis y-axis | 此处 x 轴表示视图在 x 轴上的位置。y 轴表示视图在 y 轴上的位置。 |
让我们看一个 HTML DOM Style perspectiveOrigin 属性的示例 −
示例
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
background-color: #8BC6EC;
background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%);
perspective: 100px;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem auto;
}
.box {
text-align: center;
width: 200px;
height: 200px;
background-color: #db133a;
transform: rotateX(25deg);
margin: 2rem auto;
}
</style>
<body>
<h1 style="text-align:center">DOM Style perspectiveOrigin Property Demo</h1>
<div class='box'></div>
<button class="btn" onclick="set()">Set PerspectiveOrigin</button>
<script>
function set() {
document.body.style.perspectiveOrigin = "20% 50%";
}
</script>
</body>
</html>
输出

点击“设置透视原点”按钮设置红色 框的透视原点。

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

