サーチ…


ヌル状態間の遷移

    @Component({
        ...
        animations: [
            trigger('appear', [
                transition(':enter', [
                    style({
                      //style applied at the start of animation
                    }),
                animate('300ms ease-in', style({
                    //style applied at the end of animation
                }))
                ])
            ])
        ]
    })
    class AnimComponent {

    }
]

複数の状態間のアニメーション

このテンプレートの<div>50pxなり、 100pxなり、ボタンをクリックすると20pxに縮小します。

stateは、 @Componentメタデータに記述されている関連スタイルがあります。

どちらのstateがアクティブであるかのロジックは、コンポーネントロジックで管理することができます。この場合、コンポーネント変数sizeは文字列値 "small"、 "medium"または "large"を保持します。

<div>要素は、 @Componentメタデータ: [@size]="size"指定されたtriggerによってその値に応答します。

@Component({
  template: '<div [@size]="size">Some Text</div><button (click)="toggleSize()">TOGGLE</button>',
  animations: [
    trigger('size', [
      state('small', style({
        height: '20px'
      })),
      state('medium', style({
        height: '50px'
      })),
      state('large', style({
        height: '100px'
      })),
      transition('small => medium', animate('100ms')),
      transition('medium => large', animate('200ms')),
      transition('large => small', animate('300ms'))
    ])
  ]
})
export class TestComponent {

    size: string;

    constructor(){
        this.size = 'small';
    }
    toggleSize(){
        switch(this.size) {
            case 'small':
                this.size = 'medium';
                break;
            case 'medium':
                this.size = 'large';
                break;
            case 'large':
                this.size = 'small';
        }
    }
}


Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow