> 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.

# transform-origin

APISummary
## 介绍

`transform-origin` CSS 属性用于更改一个元件进行 `transform` 变换的原点。
例如，`rotate` 变换的 `transform-origin` 是旋转中心，`scale` 变换的 `transform-origin` 是缩放中心。

## 使用示例

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

**Entry:** `src/transform-origin`
**Bundle:** `dist/transform-origin.lynx.bundle`

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

const TransformOrigin = () => {
  const emptyBoxStyle = {
    position: "absolute",
    width: "100px",
    height: "100px",
    border: "1px solid black",
  } as const;

  const redBoxStyle = {
    position: "absolute",
    width: "100px",
    height: "100px",
    backgroundColor: "red",
    transform: "rotate(45rad)",
  } as const;

  const greenBoxStyle = {
    position: "absolute",
    width: "100px",
    height: "100px",
    backgroundColor: "green",
    transformOrigin: "50% top",
    transform: "rotate(45rad)",
  } as const;

  return (
    <scroll-view className="root" scroll-orientation="vertical">
      <view className="intro">
        <view style={redBoxStyle} />
        <view style={emptyBoxStyle} />
      </view>
      <view className="intro">
        <view style={greenBoxStyle} />
        <view style={emptyBoxStyle} />
      </view>
    </scroll-view>
  );
};

root.render(<TransformOrigin />);

```

v0.11.0



## 语法

```scss
/* x-offset | default */
transform-origin: 2px;
transform-origin: bottom;

/* x-offset | y-offset */
transform-origin: 3cm 2px;

/* x-offset-keyword | y-offset */
transform-origin: left 2px;

/* x-offset-keyword | y-offset-keyword */
transform-origin: right top;

/* x-offset | y-offset */
transform-origin: 2px 30%;

/* x-offset-keyword | y-offset */
transform-origin: left 5px;

/* x-offset-keyword | y-offset-keyword */
transform-origin: right bottom;
```

`transform-origin` 属性的值可以为一个或两个。**第一个值表示 `x-offset`**，**第二个值表示 `y-offset`**，**两者之间使用空格分隔**。

### 取值

#### x-offset

`x-offset` 的值可以为长度 `<length>`、百分比 `<x-percentage>`、关键字 `<x-offset-keyword>`

- **length**
  长度值，单位为常见的 px,rem,rpx 等。

- **x-percentage**
  相对于父亲 View **宽度 Width** 的百分比。

- **x-offset-keyword**

| Keyword | Value |
| ------- | ----- |
| left    | 0%    |
| center  | 50%   |
| right   | 100%  |

#### y-offset

`y-offset` 的值可以为长度 `<length>`、百分比 `<y-percentage>`、关键字 `<y-offset-keyword>`

- **length**
  长度值，单位为常见的 px,rem,rpx 等。

- **y-percentage**
  相对于父亲 View **高度 Height** 的百分比。

- **y-offset-keyword**

| Keyword | Value |
| ------- | ----- |
| top     | 0%    |
| center  | 50%   |
| bottom  | 100%  |

## 形式定义

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


## 与 Web 的区别

- 不支持对 z 轴设置 transform-origin

## 注意事项

- transform-origin 的第一个值始终表示 `x-offset`，第二个值始终表示 `y-offset`，请不要写反。

## 兼容性

**Compatibility Table**

**Query:** `css.properties.transform-origin`

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

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

**`transform-origin`**

**Specifications:**

