- :enter
, , , , , , , , , .
- , : (@animation.done)="onDone(event)"
.
<div>
, , - . , 0px (50vh
).
StackBlitz, .
component.html
<div [@extend]="state" (@extend.done)="onDone(event)" class="animation-div div-top"></div>
<div class="main-div">
<a (click)="goTo()">Link 1</a>
</div>
<div [@extend]="state" class="animation-div div-bottom"></div>
component.ts
import { Component, OnInit } from '@angular/core';
import { extend } from '../animations';
import { Router } from '@angular/router';
@Component({
selector: 'home',
templateUrl: './home.component.html',
animations: [extend],
styleUrls: ['../app.component.css']
})
export class HomeComponent implements OnInit {
state = 'out';
constructor(private router: Router) { }
ngOnInit() {
this.state = 'out';
}
onDone($event) {
if (this.state === 'in') {
this.router.navigate(['shop']);
}
}
goTo() {
this.state = 'in';
}
}
animations.ts
import { animate, state, style, transition, trigger } from '@angular/core';
export const transitionTime = '1.5s';
export const extend =
trigger('extend', [
state('in', style({ height: '50vh' })),
state('out', style({ height: '0px' })),
transition(':enter', [
style({
height: '50vh'
}),
animate(transitionTime, style({
height: '0px'
}))
]),
transition('* => *', [
animate(transitionTime)
])
]);
component.css
.animation-div {
height: 0px;
background-color: gray;
width: 100%;
}
.div-top {
position: absolute;
top: 0px;
}
.div-bottom {
position: absolute;
bottom: 0px;
}
.main-div {
position: absolute;
top: 50px;
z-index: -1;
}