【发布时间】:2018-09-10 17:40:11
【问题描述】:
我正在使用 Angular 6 为列表制作动画。这里的想法是我想单击一个字幕部分,然后让 div 向下滑动到它的最后一个元素,首先呈现列表的整个高度。之后选项将淡入保留空间。
现在我的动画效果完全符合我的要求,但让我发疯的部分是:页面上的元素移动时会出现视觉上的抖动。 html 上有一个 ngIf 条件,它只允许块在它有元素的情况下呈现。我看到的页面上的视觉抖动来自被添加到 DOM 的 div。添加 div 后,它会将其下方的元素向下移动约 10-20px。
我尝试使用高度大致相同的不间断空格块,但这似乎夸大了响应,只会使它看起来更糟——一个元素不会消失/出现,直到动画元素完成其序列。有什么想法吗?
这是 html 示例:
<div class="uploaded-files" [@fadeAnimation]="getToggleState()">
<div *ngFor="let document of documentation">
<div *ngIf="getToggleState()" class="uploaded-file-iterator">
<div class="uploaded-filenames">{{document.fileName}}</div>
<button mat-button (click)="removeDocument(document.uploadId)" class="warn-ctrl-btn">
<i class="fa fa-times-circle"></i>
</button>
</div>
</div>
这是动画:
trigger('fadeAnimation', [
transition( '* => *', [
query(':enter',
[
style({ opacity: 0, height: 0 })
],
{ optional: true }
),
query(':leave',
[
style({ opacity: 1, height: '*' }),
sequence([
animate('0.4s', style({ opacity: 0 })),
animate('0.5s', style({ height: 0 })),
])
],
{ optional: true }
),
query(':enter',
[
style({ opacity: 0, height: 0 }),
sequence([
animate('.4s', style({ height: '*' })),
animate('.5s', style({ opacity: 1 }))
])
],
{ optional: true }
)
])
]);
【问题讨论】: