
# 语法

Glaze 动画字符串遵循一个简单的模式：

```
[breakpoint][selector]:state:properties
```

下面来逐步说明。

## 状态

每个动画都需要一个状态，可以是 `from`、`to`，也可以两者都有。

### from

从这些值开始，动画会过渡到元素的自然状态：

```html
<div data-animate="from:opacity-0"></div>
```

### to

从当前状态过渡到这些值：

```html
<div data-animate="to:xPercent-50"></div>
```

### fromTo

若要在两个特定状态之间制作动画，请同时使用两者（[fromTo，位于 GSAP](<https://gsap.com/docs/v3/GSAP/gsap.fromTo()>)）：

```html
<div data-animate="from:opacity-0.5 to:opacity-1"></div>
```

## 属性

在状态之后，列出动画属性，并用竖线（`|`）分隔：

```html
<div data-animate="to:opacity-1|yPercent-10|duration-0.5"></div>
```

字符串会在连字符（`-`）处分割并解析，前半部分是属性名称，后半部分是属性值。值会自动转换为合适的类型（数字、布尔值或字符串）。

### 嵌套属性

嵌套值请使用点号：

```html
<div data-animate="to:scale.x-2|scale.y-2"></div>
```

这会创建 `{ scale: { x: 2, y: 2 } }`。

### 负值

将负值括在方括号中：

```html
<div data-animate="to:xPercent-[-50]"></div>
```

### 含空格的值

请用下划线代替空格：

```html
<div data-animate="to:boxShadow-[0_0_50px_20px_red]"></div>
```

## 断点

在开头添加 `@breakpoint:`，即可仅在特定屏幕尺寸下运行动画：

```html
<div data-animate="@sm:from:opacity-0"></div>
```

只有屏幕符合你的 `sm` 断点时才会播放动画。

## 选择器

使用方括号表示法定位子元素，而非元素本身：

```html
<div data-animate="[&>h1]:to:opacity-1|stagger-0.25">
  <h1>One</h1>
  <h1>Two</h1>
  <h1>Three</h1>
</div>
```

`&` 指向父元素，因此 `[&>h1]` 表示“所有 h1 子元素”。

你可以将选择器与断点结合使用：

```html
<div data-animate="@sm:[&>h1]:to:opacity-1|stagger-0.25">
  <h1>...</h1>
  <h1>...</h1>
  <h1>...</h1>
</div>
```

## 综合示例

来看一个复杂示例：

```html
<div
  data-animate="@lg:[&>div]:from:opacity-0|y-50|stagger-0.1|duration-0.5|ease-power2.out"
>
  <div>Card 1</div>
  <div>Card 2</div>
  <div>Card 3</div>
</div>
```

这段配置的意思是：“在大屏幕上，为所有 div 子元素添加动画，从透明度 0 和 y 轴位置 50 开始，并设置交错效果。”
