# Class: KeyframeAnimation

`Keyframe`动画。

## Hierarchy

- [`Animation`](Animation)

  ↳ **`KeyframeAnimation`**

## Table of contents

### Constructors

- constructor

### Events

- onInit
- onPause
- onPlay
- onResume
- onStop
- onUpdate

### Properties

- clipNames

### Accessors

- scene

## Constructors

### constructor

• **new KeyframeAnimation**(`_scene`, `data`)

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `_scene` | [`Scene`](Scene) | 场景实例。 |
| `data` | [`IKeyframeAnimationData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IKeyframeAnimationData) | 初始化动画数据。 |

#### Inherited from

[Animation](Animation).[constructor](Animation#constructor)

## Events

### onInit

▸ **onInit**(`data`): `void`

动画初始化时执行的生命周期，只会执行一次。

#### Parameters

| Name | Type |
| :------ | :------ |
| `data` | [`IKeyframeAnimationData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IKeyframeAnimationData) |

#### Returns

`void`

#### Inherited from

[Animation](Animation).[onInit](Animation#onInit)

___

### onPause

▸ **onPause**(`el`): `void`

在动画暂停时执行的回调。

#### Parameters

| Name | Type |
| :------ | :------ |
| `el` | [`Element`](Element) |

#### Returns

`void`

#### Inherited from

[Animation](Animation).[onPause](Animation#onPause)

___

### onPlay

▸ **onPlay**(`el`, `clipName`, `options`): [`IKeyframeAnimationInfo`](/miniprogram/dev/reference/xr-frame/api/interfaces/IKeyframeAnimationInfo)

动画开始播放时执行的生命周期。

#### Parameters

| Name | Type |
| :------ | :------ |
| `el` | [`Element`](Element) |
| `clipName` | `string` |
| `options` | [`IKeyframeAnimationOptions`](/miniprogram/dev/reference/xr-frame/api/interfaces/IKeyframeAnimationOptions) |

#### Returns

[`IKeyframeAnimationInfo`](/miniprogram/dev/reference/xr-frame/api/interfaces/IKeyframeAnimationInfo)

返回本次播放片段的参数，必须包括时长`duration`(s)，可选循环次数`loop`、延迟`delay`和方向`direction`。

#### Inherited from

[Animation](Animation).[onPlay](Animation#onPlay)

___

### onResume

▸ **onResume**(`el`): `void`

在动画从暂停状态唤醒时执行的回调。

#### Parameters

| Name | Type |
| :------ | :------ |
| `el` | [`Element`](Element) |

#### Returns

`void`

#### Inherited from

[Animation](Animation).[onResume](Animation#onResume)

___

### onStop

▸ **onStop**(`el`): `void`

在动画停止时执行的回调。

#### Parameters

| Name | Type |
| :------ | :------ |
| `el` | [`Element`](Element) |

#### Returns

`void`

#### Inherited from

[Animation](Animation).[onStop](Animation#onStop)

___

### onUpdate

▸ **onUpdate**(`el`, `progress`, `reverse`): `void`

在动画更新时执行的回调。

#### Parameters

| Name | Type |
| :------ | :------ |
| `el` | [`Element`](Element) |
| `progress` | `number` |
| `reverse` | `boolean` |

#### Returns

`void`

#### Inherited from

[Animation](Animation).[onUpdate](Animation#onUpdate)

## Properties

### clipNames

• **clipNames**: `string`[]

动画所有的片段名字，必须在`onInit`中被初始化。

#### Inherited from

[Animation](Animation).[clipNames](Animation#clipNames)

## Accessors

### scene

• `get` **scene**(): [`Scene`](Scene)

场景实例。

#### Returns

[`Scene`](Scene)
