Skip to content

Instantly share code, notes, and snippets.

@allenhwkim
Last active July 2, 2020 04:51
Show Gist options
  • Select an option

  • Save allenhwkim/686481268ca76c311f44cbd8ecce3a43 to your computer and use it in GitHub Desktop.

Select an option

Save allenhwkim/686481268ca76c311f44cbd8ecce3a43 to your computer and use it in GitHub Desktop.
Collection of Angular animations
import { trigger, transition, style, animate, query, stagger } from '@angular/animations';
export const fadeAnimation = trigger('fadeAnimation', [
transition(':enter', [
style({ opacity: 0 }), animate('300ms', style({ opacity: 1 }))]
),
transition(':leave',
[style({ opacity: 1 }), animate('300ms', style({ opacity: 0 }))]
)
]);
export const listAnimation = trigger('listAnimation', [
transition('* <=> *', [
query(':enter',
[style({ opacity: 0 }), stagger('60ms', animate('600ms ease-out', style({ opacity: 1 })))],
{ optional: true }
),
query(':leave',
animate('300ms', style({ opacity: 0 })),
{ optional: true}
)
])
]);
<b @fadeAnimation *ngIf="show">fade animation</b>
<ul [@listAnimation]="items.length" class="items">
<li *ngFor="let item of items" class="item">{{item}}</li>
</ul>
import { Component } from '@angular/core';
import { fadeAnimation, listAnimation} from './app.animations';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
animations: [fadeAnimation, listAnimation]
})
export class AppComponent {
items = [...this.itemsOrg, ...this.itemsOrg];
}
@NgModule({
imports: [ BrowserModule, FormsModule, BrowserAnimationsModule ],
declarations: [ AppComponent, HelloComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment