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

# animation

APISummary
## 介绍

animation 属性是 [animation-name](/next/zh/api/css/properties/animation-name.md), [animation-duration](/next/zh/api/css/properties/animation-duration.md), [animation-timing-function](/next/zh/api/css/properties/animation-timing-function.md), [animation-delay](/next/zh/api/css/properties/animation-delay.md), [animation-iteration-count](/next/zh/api/css/properties/animation-iteration-count.md), [animation-direction](/next/zh/api/css/properties/animation-direction.md), [animation-fill-mode](/next/zh/api/css/properties/animation-fill-mode.md), [animation-play-state](/next/zh/api/css/properties/animation-play-state.md) 属性的一个简写属性形式。

## 使用示例

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

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

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

const Keyframes = () => {
  const [flag, setFlag] = useState(true);

  const transProperties = ["translateX", "translateY", "translateXY"];
  const rotateProperties = ["rotateZ", "rotateX", "rotateY"];
  const scaleProperties = ["scaleX", "scaleY", "scaleXY"];
  const flipProperties = ["flipX", "flipY", "flipXY"];
  const otherProperties = ["background-color", "opacity"];

  const containerHeightStyle = {
    height: "200rpx",
  };

  const columnWidthStyle = {
    width: "250rpx",
  };

  const rotateHeightStyle = {
    height: "150rpx",
  };

  const scaleImageStyle = {
    marginLeft: "15px",
    marginTop: "30px",
  };

  const otherStyle = {
    marginLeft: "15px",
    marginTop: "15px",
  };

  const getAnimationStyle = (name: string) => ({
    animation: `${name}-ani 2s ease 0s infinite alternate both running` as const,
  });

  return (
    <scroll-view scroll-orientation="vertical" className="fd-col container">
      <text className="h1">keyframes animation</text>
      <view className="sep"></view>
      <view className="fd-col group pd5">
        <text className="button h2">translate animation</text>
        <view className="fd-row" style={containerHeightStyle}>
          {transProperties.map((item, index) => (
            <view style={columnWidthStyle} key={`trans-${index}`} className="fd-col mg5">
              <text className="h3 mgl15">{item}</text>
              <image style={getAnimationStyle(item)} className="ani-size mg5 mgl15 mgt15" src={lynxImage} />
            </view>
          ))}
        </view>
      </view>
      <view className="sep"></view>

      <view className="fd-col group pd5">
        <text className="button h2">rotate animation</text>
        <view className="fd-row" style={rotateHeightStyle}>
          {rotateProperties.map((item, index) => (
            <view style={columnWidthStyle} key={`rotate-${index}`} className="fd-col mg5">
              <text className="h3 mgl15">{item}</text>
              <image style={getAnimationStyle(item)} className="ani-size mg5 mgl15 mgt15" src={lynxImage} />
            </view>
          ))}
        </view>
      </view>
      <view className="sep"></view>

      <view className="fd-col group pd5">
        <text className="button h2">scale animation</text>
        <view className="fd-row" style={containerHeightStyle}>
          {scaleProperties.map((item, index) => (
            <view style={columnWidthStyle} key={`scale-${index}`} className="fd-col mg5">
              <text className="h3 mgl15">{item}</text>
              <image style={{ ...getAnimationStyle(item), ...scaleImageStyle }} className="ani-size" src={lynxImage} />
            </view>
          ))}
        </view>
      </view>
      <view className="sep"></view>

      <view className="fd-col group pd5">
        <text className="button h2">flip animation</text>
        <view className="fd-row" style={containerHeightStyle}>
          {flipProperties.map((item, index) => (
            <view style={columnWidthStyle} key={`flip-${index}`} className="fd-col mg5">
              <text className="h3 mgl15">{item}</text>
              <image style={getAnimationStyle(item)} className="ani-size mg5 mgl15 mgt15" src={lynxImage} />
            </view>
          ))}
        </view>
      </view>
      <view className="sep"></view>

      <view className="fd-col group pd5">
        <text className="button h2">bg-color opacity animation</text>
        <view className="fd-row" style={containerHeightStyle}>
          {otherProperties.map((item, index) => (
            <view style={columnWidthStyle} key={`other-${index}`} className="fd-col mg5">
              <text className="h4 mgl15">{item}</text>
              <view className="base"></view>
              <view
                style={{
                  animation: `${item}-ani 2s ease 0s infinite alternate both ${flag ? "running" : "paused"}`,
                  ...otherStyle,
                }}
                className="ani-size"
              />
            </view>
          ))}
        </view>
      </view>
      <view className="sep"></view>
    </scroll-view>
  );
};

root.render(<Keyframes />);

```

v0.11.0



## 语法

```css
/* @keyframes name | duration | timing-function | delay |
   iteration-count | direction | fill-mode | play-state*/
animation: slidein 3s ease-in 1s 2 reverse both paused;

/* @keyframes name | duration | timing-function | delay */
animation: slidein 3s linear 1s;

/* @keyframes name | duration */
animation: slidein 3s;

/* Multiple animations */
animation:
  slidein 3s ease-in 1s 2 reverse both paused,
  ani_scale 3s linear 1s;
```

## 注意事项

:::caution

- 在写 CSS `@keyframes` 时，建议不要省略 `0%` (或者叫 `from`) 阶段和 `100%` (或者叫 `to`) 阶段的值。若起始阶段和结束阶段的值没有指定，我们会使用节点的当前属性值，由于系统限制，Android 系统的 transform 属性可能会有问题。

:::

## 形式定义

| 初始值 | animation-name: none
animation-duration: 0s
animation-timing-function: ease
animation-delay: 0s
animation-iteration-count: 1
animation-direction: normal
animation-fill-mode: none
animation-play-state: running |
| 适用元素 | all elements |
| 是否支持继承 | no |
| 是否支持动画 | no |


## 形式语法

animation 可以指定多组动画，每组动画内属性使用空格分隔，每组动画之间使用逗号分隔。

```
animation: <animation-name> || <animation-duration> ||
  <animation-timing-function> || <animation-delay> ||
  <animation-iteration-count> || <animation-direction> || <animation-fill-mode>
  || <animation-play-state>;
```

## 动画事件

- [动画事件](/next/zh/api/lynx-api/event/animation-event.md)

## 扩展阅读

- [animation](/next/zh/api/css/properties/animation.md)
- [animation-name](/next/zh/api/css/properties/animation-name.md)
- [animation-duration](/next/zh/api/css/properties/animation-duration.md)
- [animation-timing-function](/next/zh/api/css/properties/animation-timing-function.md)
- [animation-delay](/next/zh/api/css/properties/animation-delay.md)
- [animation-iteration-count](/next/zh/api/css/properties/animation-iteration-count.md)
- [animation-direction](/next/zh/api/css/properties/animation-direction.md)
- [animation-fill-mode](/next/zh/api/css/properties/animation-fill-mode.md)
- [animation-play-state](/next/zh/api/css/properties/animation-play-state.md)
- [CSS 动画事件](/next/zh/api/lynx-api/event/animation-event.md)
- [Animated API](/next/zh/api/lynx-api/lynx/lynx-animate-api.md)

## 兼容性

**Compatibility Table**

**Query:** `css.properties.animation`

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

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

**`animation`**

**Specifications:**

