gpt4 book ai didi

angular - 如何动画 :enter & :leave transitions conditionally in Angular?

转载 作者:太空狗 更新时间:2023-10-29 18:22:05 26 4
gpt4 key购买 nike

我有一个列表,其中的项目有这样的动画:

<li @animation>

这是我的动画触发器:

trigger('animation', [
transition(':enter', [
style({ height: '0px', 'padding-top': '0', 'padding-bottom': '0'}), // initial
animate('0.5s',
style({ height: '*', 'padding-top': '*', 'padding-bottom': '*'})) // final
]),
transition(':leave', [
style({ height: '*', 'padding-top': '*', 'padding-bottom': '*', opacity: 1}), // initial
animate('0.5s',
style({ height: '0px', 'padding-top': '0', 'padding-bottom': '0', opacity: 0})) // final
])
])

我如何有条件地为特定项目打开/关闭此动画? 实际上我正在寻找某事。像这样:

<li [@animation]=item.isAnimated>

根本不起作用。

不幸的是,Angular 文档中只有一句话是关于这个的:

For elements entering or leaving a page (inserted or removed from the DOM), you can make the animations conditional. For example, use *ngIf with the animation trigger in the HTML template.

但是当我将动画注释与 *ngIf 结合使用时,非动画项目显然根本不会显示:

<li *ngIf="item.isAnimated" @animation>

无论 isAnimated 标志如何,我都想进一步显示所有项目。我只想打开/关闭特定项目的动画。

最佳答案

根据 Angular IO :

当为 true 时,特殊动画控件绑定(bind) @.disabled 绑定(bind)会阻止所有动画呈现。将 @.disabled 绑定(bind)放在元素上以禁用元素本身的动画,以及元素内的任何内部动画触发器。

以下示例展示了如何使用此功能:

@Component({
selector: 'my-component',
template: `
<div [@.disabled]="isDisabled">
<div [@childAnimation]="exp"></div>
</div>
`,
animations: [
trigger("childAnimation", [
// ...
])
]
})
class MyComponent {
isDisabled = true;
exp = '...';
}

当@.disabled 为真时,它会阻止@childAnimation 触发器以及任何内部动画进行动画处理。

关于angular - 如何动画 :enter & :leave transitions conditionally in Angular?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54862903/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com