角度动画:填充不是高度为 0->* 的动画

akc*_*soy 1 css angular angular-animations

我用 Angular 写了一个抽屉动画。看起来像这样:

  transition(':enter', [
    style({height: '0', opacity: 0}),

    group([
      animate(300, style({height: '*'})),
      animate('300ms ease-in-out', style({'opacity': '1'}))
    ])

  ]) ,
  transition(':leave', [
    style({height: '*', opacity: 1}),

    group([
      animate(300, style({height: 0})),
      animate('300ms ease-in-out', style({'opacity': '0'}))
    ] )
    ])
Run Code Online (Sandbox Code Playgroud)

我的主 div(此动画粘贴的位置)也有一个填充(所有 4 个方向均为 20 像素)。

问题:只要 div 可见(通过 *ngIf),我的高度动画就会开始工作。但是元素的填充立即存在.. 其余的将被动画化。所以它在动画开始时有一个闪烁的效果。

我怎样才能得到填充动画?或者我应该改变什么?

mik*_*era 6

要在 高度上实现平滑动画,div您还应该为padding-toppadding-bottom属性设置动画:

transition(':enter', [
  style({height: '0', opacity: 0, 'padding-top': '0', 'padding-bottom': '0'}),

  group([
    animate(300, style({height: '*', 'padding-top': '*', 'padding-bottom': '*'})),
    animate('300ms ease-in-out', style({'opacity': '1'}))
  ])

]) ,
transition(':leave', [
  style({height: '*', opacity: 1, 'padding-top': '*', 'padding-bottom': '*'}),

  group([
    animate(300, style({height: 0, 'padding-top': 0, 'padding-bottom': 0})),
    animate('300ms ease-in-out', style({'opacity': '0'}))
  ] )
])
Run Code Online (Sandbox Code Playgroud)