Here is a custom animation created using the built-in Angular library:
//slideDown-animation.ts
import { animate, style, group, state, transition, trigger } from '@angular/animations';
export const slideDownAnimation = trigger('slideDownAnimation', [
state('in', style({
'max-height': '1000px', 'opacity':1, 'overflow': 'visible'
})),
state('out', style({
'max-height': '0px', 'opacity':1, 'overflow': 'hidden'
})),
transition('in => out', [group([
animate('300ms ease-in-out', style({
'opacity': '0'
})),
animate('300ms ease-in-out', style({
'max-height': '0px'
})),
animate('300ms ease-in-out', style({
'visibility': 'hidden'
}))
]
)]),
transition('out => in', [group([
animate('300ms ease-in-out', style({
'visibility': 'visible'
})),
animate('300ms ease-in-out', style({
'max-height': '500px'
})),
animate('300ms ease-in-out', style({
'opacity': '1'
}))
]
)])
]);
//in component.ts
import { slideDownAnimation } from "src/app/shared/animations/slideDown-animation";
@Component({
selector: 'app-checkout',
templateUrl: './checkout.component.html',
styleUrls: ['./checkout.component.css'],
animations: [modalAnimations,slideDownAnimation]
})
export class...
<!-- component.html -->
<div [@slideDownAnimation]="YourBooleanVariable?'in':'out'"></div>
Check out a demo of this animation in action:
https://stackblitz.com/edit/angular-ivy-ppyssn?file=src/app/slide.animation.ts