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?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With