Angular 2+多个动画随机失败

问题描述 投票:1回答:1

我需要多个div同时淡出。

动画已经实现了10个不同的div。

当动画被触发时,它完全正常,除了它不适用于具有相同代码的1 div。

这是动画代码:

   trigger('fadeInOut', [
  state('hide', style({
    opacity: 0,
    display: 'none'
  })),
  state('display', style({
    opacity: 1,
    display: 'inline'
  })),
  transition('display => hide', animate('100ms ease-out')),
  transition('hide => display', animate('100ms ease-out'))  
])

这是html部分

        <a href="#" class="list-group-item" data-parent="#sidebar">
            <div class="icon-container">
                <i class="fa fa-briefcase"></i>
            </div>
            <div class="fadable" [@fadeInOut]='fadeState'>
                <span>Projects</span>
                <span class="expand-icon">
                    <i class="fa fa-plus-square-o"></i>
                </span>
            </div>
        </a>

还有其他10个具有相同代码的锚点......

有人可以帮忙吗?

angular animation angular-animations
1个回答
0
投票

几天我有同样的问题,现在我为我修好了。我还有两个元素,其中设置了相同的动画触发器。第一个动画正确,但另一个甚至没有开始。 (并指定了“ng-animate-queued”类)

在我的情况下的问题是,同时,第二个元素必须是动画(@bounce),父容器也播放动画(@galleryShadow),迫使内部元素等待(可能由角度动画决定性能)发动机?)。

因为我在这里找到了一个可能的解决方案Angular Animations: Animate Parent and Child Elements。我试图将我的外部动画分组以查询内部触发器并为其调用animateChild()。

它解决了我的问题。也许它可以帮助你或任何其他人面对这种行为(像我一样)。

trigger('galleryShadow', [
  state('stage-chosen', style({ display: 'none', transform: 'translateX(100%)' })),
  state('compare-chosen', style({ display: 'none', transform: 'none' })),
  state('presenting', style({ display: '*', transform: 'translate(50%)' })),

  transition('compare-chosen => presenting', [
      style({ display: '*', transform: 'translateX(100%)' }),
      group([
        query('@bounce', animateChild()),
        animate('200ms ease-out')
      ]),
    ]
  ),
  transition('stage-chosen => presenting', [
      style({ display: '*' }),
      group([
        query('@bounce', animateChild()),
        animate('200ms ease-out')
      ]),
    ]
  ),
  transition('presenting => stage-chosen', animate('400ms ease-in')),
  transition('presenting => compare-chosen', animate('400ms ease-in'))
])
© www.soinside.com 2019 - 2024. All rights reserved.