填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

AnimationBuilder

一种可注入服务,可在 Angular 组件或指令中以编程的方式生成动画序列。由 BrowserAnimationsModule 或 NoopAnimationsModule 提供。

An injectable service that produces an animation sequence programmatically within an Angular component or directive. Provided by the BrowserAnimationsModule or NoopAnimationsModule.

      
      abstract class AnimationBuilder {
  abstract build(animation: AnimationMetadata | AnimationMetadata[]): AnimationFactory
}
    

方法

建立一个工厂来产生所定义的动画。

Builds a factory for producing a defined animation.

See also:

      
      abstract build(animation: AnimationMetadata | AnimationMetadata[]): AnimationFactory
    
参数
animation AnimationMetadata | AnimationMetadata[]

可复用的动画定义。

A reusable animation definition.

返回值

可以为所定义的动画创建播放器的工厂对象。

AnimationFactory: A factory object that can create a player for the defined animation.

使用说明

要使用此服务,请将其作为依赖项添加到你的组件或指令中。该服务与你的组件一起实例化。

To use this service, add it to your component or directive as a dependency. The service is instantiated along with your component.

应用通常不需要创建自己的动画播放器,但是如果需要,请按照以下步骤操作:

Apps do not typically need to create their own animation players, but if you do need to, follow these steps:

  1. 使用 build() 方法创建一个用 animate() 函数创建的程序性动画。该方法返回一个 AnimationFactory 实例。

    Use the build() method to create a programmatic animation using the animate() function. The method returns an AnimationFactory instance.

  2. 使用工厂对象创建 AnimationPlayer 并将其附加到 DOM 元素。

    Use the factory object to create an AnimationPlayer and attach it to a DOM element.

  3. 使用播放器对象以编程方式控制动画。

    Use the player object to control the animation programmatically.

例如:

For example:

      
      // import the service from BrowserAnimationsModule
import {AnimationBuilder} from '@angular/animations';
// require the service as a dependency
class MyCmp {
  constructor(private _builder: AnimationBuilder) {}

  makeAnimation(element: any) {
    // first define a reusable animation
    const myAnimation = this._builder.build([
      style({ width: 0 }),
      animate(1000, style({ width: '100px' }))
    ]);

    // use the returned factory object to create a player
    const player = myAnimation.create(element);

    player.play();
  }
}