简体   繁体   English

无法在嵌套的ngRepeat上触发动画

[英]Can't trigger animation on nested ngRepeat

I can't figure out how to trigger animations on a nested ngRepeat with Angular. 我无法弄清楚如何使用Angular在嵌套的ngRepeat上触发动画。

The CSS class ".test" is animated. CSS类“.test”是动画的。 When using ".test" on the inner ngRepeat it doesn't work ( Plunker ): 在内部ngRepeat上使用“.test”时,它不起作用( Plunker ):

<div ng-repeat="section in sections">
  <div ng-repeat="item in section.items" class="test">
    <h2>{{item.title}}</h2>
  </div>
</div>

When using ".test" on the outer ngRepeat it does work ( Plunker ): 在外部ngRepeat上使用“.test”时,它确实有效( Plunker ):

<div ng-repeat="section in sections">
  <div ng-repeat="item in section.items" class="test">
    <h2>{{item.title}}</h2>
  </div>
</div>

You probably need to add ngAnimateChildren attribute on the parent container, and update the css as well. 您可能需要在父容器上添加ngAnimateChildren属性,并更新css。

Try:- 尝试:-

<div ng-repeat="section in sections" ng-animate-children>
  <div ng-repeat="item in section.items" class="test">
    <h2>{{item.title}}</h2>
  </div>
</div>

and

.test.ng-move,
.test.ng-enter,
.test.ng-leave {
  -webkit-transition: all 0.3s  ease-out;
    transition: all 0.3s  ease-out;
}

.test.ng-leave.ng-leave-active,
.test.ng-move,
.test.ng-enter {
   opacity:0;
   -webkit-transform: translate(-20px, 0);
    transform: translate(-20px, 0);
}

.test.ng-leave,
.test.ng-move.ng-move-active,
.test.ng-enter.ng-enter-active {
 opacity:1;
   -webkit-transform: translate(0, 0);
    transform: translate(0, 0);
}

Plnkr Plnkr

Found this from the doc 文档中找到了这个

Keep in mind that, by default, if an animation is running, any child elements cannot be animated until the parent element's animation has completed. 请记住,默认情况下,如果动画正在运行,则在父元素的动画完成之前,不能对任何子元素进行动画处理。 This blocking feature can be overridden by placing the ng-animate-children attribute on a parent container tag. 可以通过将ng-animate-children属性放在父容器标记上来覆盖此阻止功能。

Even though there is no animation on the parent repeat, it seems like ng-animate just ignores any further animation on its children. 尽管父重复上没有动画,但似乎ng-animate只是忽略其子节点上的任何进一步动画。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM