Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 bind animation to pseudo element

I am trying to use Angular2 animation system, for a pseudo element :before. As per animation flow, I need to define animation state:

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'))
])]

and then attach it to a DOM element, as follows:

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

However, I want to attach this to a pseudo before element. How can I do that?

like image 735
Yuvals Avatar asked Oct 15 '16 19:10

Yuvals


People also ask

How do you add animations to Main NG module in angular 4?

In the component file, set the trigger that defines the animations as the value of the animations: property in the @Component() decorator. In the HTML template file, use the trigger name to attach the defined animations to the HTML element to be animated.

Which animation strategy would you use to apply multiple styles for a transition?

The keyframes() function in Angular allows you to specify multiple interim styles within a single transition, with an optional offset to define the point in the animation where each style change should occur.


1 Answers

Try this please this will what you want.

<style>
h1::before {
    content: url(animation.html);
}
</style>

animation.html file

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

Hope this works for you.

More about this Using Javascript in CSS

like image 200
Sergey Avatar answered Oct 05 '22 07:10

Sergey