I am new with angular and angular animations and I have a problem.
This is my html code:
<div class="main">
<div class="left" *ngIf="showLeftSide" [@slideInOutLeft]></div>
<div class="center"></div>
<div class="right" *ngIf="showRightSide" [@slideInOutRight]></div>
</div>
<div class="footer">
<button (click)="toggleLeftSide()" class="btn">Toggle Left Side</button>
<button (click)="toggleRightSide()" class="btn">Toggle Right Side</button>
</div>
What i want to do is when the left
or right
div
is sliding in or out I want that the center
div
will grow or shrink with animation at the same time that the sliding animation goes on (What I got now is that after the sliding animation finished the center
div
jumps to fill the free space).
My component code:
@Component({
selector: 'app-root',
animations: [
trigger('slideInOutLeft', [
transition(':enter', [
style({transform: 'translateX(-100%)'}),
animate('500ms', style({transform: 'translateX(0%)'}))
]),
transition(':leave', [
animate('500ms', style({transform: 'translateX(-100%)'}))
])
]),
trigger('slideInOutRight', [
transition(':enter', [
style({transform: 'translateX(100%)'}),
animate('500ms ease-in', style({transform: 'translateX(0%)'}))
]),
transition(':leave', [
animate('500ms ease-in', style({transform: 'translateX(100%)'}))
])
])
],
templateUrl: './app.component.html',
styleUrls: ['./app.component.less']
})
export class AppComponent {
showLeftSide = true;
showRightSide = true;
toggleLeftSide() {
this.showLeftSide = !this.showLeftSide;
}
toggleRightSide() {
this.showRightSide = !this.showRightSide;
}
}
My less file:
html, body {
margin: 0;
height: 100%;
overflow: hidden;
}
.main {
display: flex;
height: 95%;
.left {
background-color: midnightblue;
width: 3vw;
will-change: transform;
}
.center {
background-color: tomato;
width: 100%;
}
.right {
background-color: aquamarine;
width: 30vw;
will-change: transform;
}
}
.footer {
display: flex;
align-items: center;
justify-content: space-between;
background-color: brown;
width: 100%;
height: 5%;
.btn {
width: 5%;
}
}
I wish I could upload code snippet but I don't know how to do this for angular 7.
I hope you understand my problem and what I want, sorry for my english and thanks in advance!
Edit:
Live example: https://angular-yej9sz.stackblitz.io/ | https://stackblitz.com/edit/angular-yej9sz