diff --git a/apps/angular/46-simple-animations/src/app/animations.ts b/apps/angular/46-simple-animations/src/app/animations.ts new file mode 100644 index 000000000..d251d9332 --- /dev/null +++ b/apps/angular/46-simple-animations/src/app/animations.ts @@ -0,0 +1,38 @@ +import { + animate, + query, + stagger, + style, + transition, + trigger, +} from '@angular/animations'; + +export const fadeInAnimation = [ + trigger('horizontalAnimation', [ + transition(':enter', [ + style({ transform: 'translateX(-100%)' }), + animate('0.5s ease-in-out', style({ transform: 'translateX(0)' })), + ]), + transition(':leave', [ + style({ transform: 'translateX(0)' }), + animate('0.5s ease-in-out', style({ transform: 'translateX(-100%)' })), + ]), + ]), +]; + +export const staggerAnimation = [ + trigger('staggerAnimation', [ + transition(':enter', [ + query( + '.list-item', + [ + style({ opacity: 0, transform: 'translateY(-10px)' }), + stagger(200, [ + animate('500ms ease-in', style({ opacity: 1, transform: 'none' })), + ]), + ], + { optional: true }, + ), + ]), + ]), +]; diff --git a/apps/angular/46-simple-animations/src/app/app.component.ts b/apps/angular/46-simple-animations/src/app/app.component.ts index ae63db419..bf7dca2fb 100644 --- a/apps/angular/46-simple-animations/src/app/app.component.ts +++ b/apps/angular/46-simple-animations/src/app/app.component.ts @@ -1,8 +1,9 @@ import { Component } from '@angular/core'; +// import { fadeInAnimation, staggerAnimation } from './animations'; @Component({ - imports: [], selector: 'app-root', + // animations: [fadeInAnimation, staggerAnimation], styles: ` section { @apply flex flex-1 flex-col gap-5; @@ -15,10 +16,31 @@ import { Component } from '@angular/core'; @apply flex-1; } } + + .list .list-item { + transition-property: opacity, transform; + transition-duration: 500ms; + transition-delay: calc(200ms * var(--index)); + @starting-style { + opacity: 0; + transform: translateY(-10px); + } + } + + .fade-in { + transition-property: opacity, transform; + transition-duration: 500ms; + transition-timing-function: ease-in-out; + @starting-style { + opacity: 0; + transform: translateX(-100%); + } + } `, template: `
@@ -50,38 +72,25 @@ import { Component } from '@angular/core';