> 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-fill-mode

APISummary
## 介绍

`animation-fill-mode` 设置 CSS 动画在执行之前和之后如何将样式应用于其目标

## 使用示例

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

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

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

const AnimationFillMode = () => {
  const noneProperties = ["none"];
  const forwardsProperties = ["forwards"];
  const backwardsProperties = ["backwards"];
  const bothProperties = ["both"];

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

  const columnStyle = {
    width: "350px",
  };

  const getAnimationStyle = (fillMode: string) => ({
    animation: `ani 3s ease 2s 1 normal ${fillMode} running` as const,
  });

  return (
    <scroll-view scroll-orientation="vertical" className="fd-col container">
      <text className="h1">keyframes animation demo: fillmode</text>
      <text className="h4">From--&gt; transform: translateX(50px);background-color: blue;</text>
      <text className="h4">To--&gt; transform: translateX(200px);background-color: red;</text>
      <view className="sep"></view>

      <view className="fd-col group pd5">
        <text className="button h2">none</text>
        <view className="fd-row" style={containerStyle}>
          {noneProperties.map(item => (
            <view style={columnStyle} className="fd-col mg5" key={item}>
              <text className="h4 mgl15">{item}</text>
              <view flatten={false} style={getAnimationStyle(item)} className="ani-size mg5" />
            </view>
          ))}
        </view>
      </view>
      <view className="sep"></view>

      <view className="fd-col group pd5">
        <text className="button h2">forwards</text>
        <view className="fd-row" style={containerStyle}>
          {forwardsProperties.map(item => (
            <view style={columnStyle} className="fd-col mg5" key={item}>
              <text className="h4 mgl15">{item}</text>
              <view flatten={false} style={getAnimationStyle(item)} className="ani-size mg5" />
            </view>
          ))}
        </view>
      </view>
      <view className="sep"></view>

      <view className="fd-col group pd5">
        <text className="button h2">backwards</text>
        <view className="fd-row" style={containerStyle}>
          {backwardsProperties.map(item => (
            <view style={columnStyle} className="fd-col mg5" key={item}>
              <text className="h4 mgl15">{item}</text>
              <view flatten={false} style={getAnimationStyle(item)} className="ani-size mg5" />
            </view>
          ))}
        </view>
      </view>
      <view className="sep"></view>

      <view className="fd-col group pd5">
        <text className="button h2">both</text>
        <view className="fd-row" style={containerStyle}>
          {bothProperties.map(item => (
            <view style={columnStyle} className="fd-col mg5" key={item}>
              <text className="h4 mgl15">{item}</text>
              <view flatten={false} style={getAnimationStyle(item)} className="ani-size mg5" />
            </view>
          ))}
        </view>
      </view>
      <view className="sep"></view>
    </scroll-view>
  );
};

root.render(<AnimationFillMode />);

```

v0.11.0



## 语法

```css
/* Single animation */
animation-fill-mode: none;
animation-fill-mode: forwards;
animation-fill-mode: backwards;
animation-fill-mode: both;

/* Multiple animations */
animation-fill-mode: none, backwards;
animation-fill-mode: both, forwards, none;
```

### 取值

#### none

当动画未执行时，动画将不会将任何样式应用于目标，而是已经赋予给该元件的 CSS 规则来显示该元件。这是默认值。

#### forwards

动画结束时将最后一个关键帧的值设置给 View。最后一个关键帧取决于 [animation-direction](/next/zh/api/css/properties/animation-direction.md) 和 [animation-iteration-count](/next/zh/api/css/properties/animation-iteration-count.md) 的值：

| animation-direction | animation-iteration-count | last keyframe encountered |
| ------------------- | ------------------------- | ------------------------- |
| normal              | even or odd               | 100% or to                |
| reverse             | even or odd               | 0% or from                |
| alternate           | even                      | 0% or from                |
| alternate           | odd                       | 100% or to                |
| alternate-reverse   | even                      | 100% or to                |
| alternate-reverse   | odd                       | 0% or from                |

#### backwards

动画开始时将第一个关键帧的值设置给 View。第一个关键帧取决于 [animation-direction](/next/zh/api/css/properties/animation-direction.md) 和 [animation-iteration-count](/next/zh/api/css/properties/animation-iteration-count.md) 的值：

| animation-direction          | first relevant keyframe |
| ---------------------------- | ----------------------- |
| normal or alternate          | 0% or from              |
| reverse or alternate-reverse | 100% or to              |

#### both

动画将遵循 forwards 和 backwards 的规则，从而在动画开始与结束时将相应关键帧设置给 View。

## 形式定义

| 初始值 | none |
| 适用元素 | all elements |
| 是否支持继承 | no |
| 是否支持动画 | no |


## 形式语法

```css
/*none*/
animation-fill-mode: none | forwards | backwards | both;
```

## 扩展阅读

- [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 animation event](/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-fill-mode`

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

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

**`animation-fill-mode`**

**Specifications:**

