> For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt.

# perspective

APISummary
## 介绍

CSS 属性 perspective 指定了观察者与 z=0 平面的距离，使具有三维位置变换的元件产生透视效果。z>0 的三维元件比正常大，而 z\<0 时则比正常小，大小程度由该属性的值决定。

## 使用示例

**下面是一个示例: css-api**

**Entry:** `src/perspective`
**Bundle:** `dist/perspective.lynx.bundle`

```tsx
import { root, useState } from "@lynx-js/react";
import "./index.scss";

const Perspective = () => {
  const [front, setFront] = useState(false);
  const [enableAni, setEnableAni] = useState(false);

  const handleKeyframe = () => {
    setFront(!front);
  };

  const handleAni = () => {
    setEnableAni(!enableAni);
  };

  const containerStyle = {
    display: "flex" as const,
    flexDirection: "column" as const,
    width: "100%",
    height: "1000px",
    background: "white",
  };

  const perspectiveStyle = {
    perspective: "750px",
  };

  return (
    <view style={containerStyle}>
      <text>Animation demo</text>

      <view className={front ? "container front" : "container back"} style={perspectiveStyle} bindtap={handleKeyframe}>
        <text>Front</text>
      </view>
      <view
        className={front ? "container1 back" : "container1 front"}
        style={perspectiveStyle}
        bindtap={handleKeyframe}
      >
        <view className="container2" />
        <text>Back</text>
      </view>
      <view className="anim-container">
        <view
          className={enableAni ? "anim-content anim-content-back backf0" : "anim-content anim-content-back backf1"}
          style={perspectiveStyle}
          bindtap={handleAni}
        >
          <text>Front</text>
          <text>Back</text>
        </view>
        <view
          className={enableAni ? "anim-content anim-content-front keyf0" : "anim-content anim-content-front keyf1"}
          style={perspectiveStyle}
          bindtap={handleAni}
        >
          <text>back</text>
        </view>
      </view>
    </view>
  );
};

root.render(<Perspective />);

```

v0.11.0



## 语法

```css
/* Keyword value */
perspective: auto;

/* <length> values */
perspective: 20px;
perspective: 3.5em;
```

### 取值

- `auto`
  没有应用 perspective 样式时的默认值。

- `[<length>]`
  指定观察者距离 `z=0` 平面的距离，为元件及其内容应用透视变换。当值为 0 或负值时，无透视变换。

## 形式定义

| 初始值 | 空值 |
| 适用元素 | 所有元件 |
| 是否支持继承 | no |
| 是否支持动画 | no |


## 形式语法

```
perspective = auto | <length [0,∞]>
```

## 与 Web 的区别

- 不同于 Web，Lynx 中 Perspective 属性**对当前节点生效**，而 Web 中 Perspective 属性**对孩子节点生效**。

## 兼容性

**Compatibility Table**

**Query:** `css.properties.perspective`

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/190-perspective.json) · [MDN](https://developer.mozilla.org/zh-CN/docs/Web/CSS/perspective)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| perspective | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |

**`perspective`**

**Specifications:**

- **Web — Supported (version unknown):** It takes effect on all its descendants.

