小编San*_*eph的帖子

如何使用 Angular2 中的基础组件将动画应用于多个组件?

在我的应用程序中,当组件使用路由从菜单加载时,我想使用一些动画。我能够成功地使用角度动画来做到这一点。我必须在单个组件中应用动画才能实现这一点。我需要知道是否有更好的方法将动画应用于一组组件或从特定基类继承的组件?

目前我已经应用了我的动画,

import { Component, OnInit } from '@angular/core';
import { routerTransition } from "../animations/animations";

@Component({
  selector: 'app-my-component',
  templateUrl: './my-component.component.html',
  styleUrls: ['./my-component.component.css'],
  animations: [routerTransition()],
  host: {'[@routerTransition]': ''}
})
export class BaseComponentComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}
Run Code Online (Sandbox Code Playgroud)

动画代码,

import {trigger, state, animate, style, transition} from '@angular/core';

export function routerTransition() {
  return slideToLeft();
}

function slideToLeft() {
  return trigger('routerTransition', [
    state('void', style({position:'fixed', width:'100%'}) ),
    state('*', style({position:'fixed', width:'100%'}) ),
    transition(':enter', [  // before 2.1: transition('void => *', [ …
Run Code Online (Sandbox Code Playgroud)

javascript inheritance animation angularjs

5
推荐指数
1
解决办法
4289
查看次数

标签 统计

angularjs ×1

animation ×1

inheritance ×1

javascript ×1