Angular2将动画绑定到伪元素

Yuv*_*als 17 angular angular-animations

我正在尝试使用Angular2动画系统,用于伪元素:before.根据动画流程,我需要定义动画状态:

animations: [
trigger('heroState', [
  state('inactive', style({
    backgroundColor: '#eee',
    transform: 'scale(1)'
  })),
  state('active',   style({
    backgroundColor: '#cfd8dc',
    transform: 'scale(1.1)'
  })),
  transition('inactive => active', animate('100ms ease-in')),
  transition('active => inactive', animate('100ms ease-out'))
])]
Run Code Online (Sandbox Code Playgroud)

然后将其附加到DOM元素,如下所示:

<ul>
<li *ngFor="let hero of heroes"
    [@heroState]="hero.state"
    (click)="hero.toggleState()">
  {{hero.name}}
</li>
Run Code Online (Sandbox Code Playgroud)

但是,我想将其附加到伪before元素.我怎样才能做到这一点?

Ser*_*gey 1

请尝试一下,这将是您想要的。

<style>
h1::before {
    content: url(animation.html);
}
</style>
Run Code Online (Sandbox Code Playgroud)

动画.html 文件

<ul>
<li *ngFor="let hero of heroes"
    [@heroState]="hero.state"
    (click)="hero.toggleState()">
  {{hero.name}}
</li>
Run Code Online (Sandbox Code Playgroud)

希望这对你有用。

有关在 CSS 中使用 Javascript 的更多信息