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

标签 javascript css angularjs angularjs-ng-repeat ng-animate

我不知道如何使用 Angular 在嵌套的 ngRepeat 上触发动画。

CSS 类“.test”是动画的。在内部 ngRepeat 上使用“.test”时它不起作用(Plunker):

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

在外部 ngRepeat 上使用“.test”时它确实有效(Plunker):

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

最佳答案

您可能需要添加 ngAnimateChildren父容器上的属性,并更新 css。

尝试:-

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

.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

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 似乎只是忽略了其子项上的任何进一步动画。

关于javascript - 无法在嵌套的 ngRepeat 上触发动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25287517/

相关文章:

javascript - 如何在nodejs中重复执行

html - ASP :TextBox; is there an "OnFocus" or CSS equivalent

AngularJS 测试 - 测试 Promise 回调中的逻辑

json - Angular.js 解析 JSON 中的 html 标签

javascript - Angular - 重新启动 http?

javascript - ng-include 使用外部模板非常慢

javascript - 访问通过设置innerHTML创建的HTML元素

Javascript 映射函数 - 将单词项传递给函数以返回 html 元素

html - 如何减少下拉菜单项之间的空间?

c# - 我如何在 css 中更改文本框的宽度?