HTML DOM Style perspective 属性

htmldomweb developmentfront end technology更新于 2024/5/23 17:16:17

HTML DOM Style perspective 属性用于返回并修改 3D 元素在 HTML 文档中的显示方式。

语法

以下是语法 −

1. 返回 perspective

object.perspective

2. 修改 perspective

object.perspective = “value”

此处,value可以为负数。

值说明
Initial将此属性值设置为默认值。
inherit从其父元素继承此属性值。
None未设置透视。
length以长度单位指定元素与视图的距离。

让我们看一个 HTML DOM Style perspective 属性的示例 −

示例

<!DOCTYPE html>
<html>
<style>
   body {
      color: #000;
      height: 100vh;
      background-color: #8BC6EC;
      background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%);
   }
   .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 perspective Property Demo</h1>
<div class='box'></div>
<button class="btn" onclick="set()">Set Perspective</button>
<script>
   function set() {
      document.body.style.perspective = "100px";
   }
</script>
</body>
</html>

输出

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


相关文章


有用资源