【发布时间】:2018-12-29 19:23:17
【问题描述】:
我是角度和角度动画的新手,但遇到了问题。
这是我的html代码:
<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>
我想要做的是当left 或right div 滑入或滑出时我希望center div 在滑动动画的同时随着动画的增长或缩小继续(我现在得到的是滑动动画完成后center div 跳转以填充空闲空间)。
我的组件代码:
@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;
}
}
我的less文件:
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%;
}
}
我希望我可以上传代码 sn-p 但我不知道如何为 angular 7 执行此操作。
我希望你能理解我的问题和我想要什么,对不起我的英语并提前感谢!
编辑:
现场示例:https://angular-yej9sz.stackblitz.io/ | https://stackblitz.com/edit/angular-yej9sz
【问题讨论】:
标签: angular animation angular-animations