angular - Angular - 在其他 div 滑出/滑入时使 div 增长/缩小
问题描述
我是角度和角度动画的新手,我遇到了问题。
这是我的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;
}
}
我的少文件:
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%;
}
}
我希望我可以上传代码片段,但我不知道如何为 Angular 7 执行此操作。
我希望你能理解我的问题和我想要的,对不起我的英语,提前谢谢!
编辑:
现场示例:https ://angular-yej9sz.stackblitz.io/ | https://stackblitz.com/edit/angular-yej9sz
解决方案
就像在 css 中一样,Angular 动画不适用于display
属性。'Center' div 调整大小跳跃是因为display:none
. 它的动画应该应用于width
属性(例如)才能工作:
state("false", style({ width: 0, display:'none' }))
推荐阅读
- azure-virtual-network - 新的 VNet 命名规则?
- python - 将 Pandas 数据帧转换为嵌套 json 的更快方法
- php - 如何生成引用相同 head.php 文件的 .php 文件?
- java - 遍历向量中的元素,以循环方式从最后一个元素环绕到第一个元素
- javascript - 如何使用 AJAX 调用返回的数据创建或填充表
- asynchronous - 使用龙卷风的 AsyncHTTPClient 与在 run_in_executor() 中包装阻塞 http 调用之间是否存在显着差异?
- typescript - Typescript 函数类型顺序问题 |
- c++ - 在 main() 中获取不带参数的命令行参数
- azure-devops - Azure DevOps iframe 中的 Blazor 路由失败
- telerik - 搜索框支持以逗号分隔的多个搜索