进入动画工作正常,但离开动画不工作。如果我将@modalFadeZoom 移动到父级,则两个转换都有效,但问题是缩放不是从模态的中心发生的,这会产生奇怪的动画。
如果我将@modalFadeZoom 移动到孩子,淡入缩小工作正常。但关闭模型时没有淡出和放大。
组件 html
<div class="modal-dialog" *ngIf="showModal">
<div class="modal-content" [@modalFadeZoom]>
<div class="modal-header">
<h5 class="modal-title">SOME TITLE</h5>
<button type="button" (click)="showModal=false" class="close" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
lorem ipsum etc etc
</div>
</div>
</div>
<div class="modal-backdrop fade show" *ngIf="showModal"></div>
ts文件
import { Component, OnInit, trigger, transition, style, animate } from '@angular/core';
@Component({
templateUrl: 'modal.template.html',
animations: [
trigger(
'modalFadeZoom',
[
transition(
':enter', [
style({ transform: 'scale(.7)', opacity: 0 }),
animate('0.3s', style({ opacity: 1, transform: 'scale(1)' })),
]
),
transition(
':leave', [
style({ opacity: 1, transform: 'scale(1)' }),
animate('5.3s', style({ opacity: 0, transform: 'scale(.7)' })),
]
),
])
]
})
export class ModalComponent implements OnInit {
private showModal = false;;
ngOnInit(): void {
this.showModal = true;
}
}
模态对话框的 CSS
.modal-dialog {
position: fixed;
top: 50%;
left: 50%;
height: auto;
z-index: 2000;
transform: translateX(-50%) translateY(-50%);
}
plnkr 链接
请注意,由于缩放,我已将 plnkr 演示动画中的动画从中心移至父级。