css - 不能错开 ngAnimate 子动画

标签 css angularjs animation css-animations ng-animate

我正在尝试使用以下 HTML 为 ngRepeat div 的子元素错开动画。

  <strong>This staggers</strong>
  <div ng-repeat="item in items" class="animate-stagger container" ng-animate-children="true">
    <div>{{item}}</div>
  </div>

  <strong>This doesn't stagger</strong>
  <div ng-repeat="item in items" class="animate-child-stagger container" ng-animate-children="true">
    <div>{{item}}</div>
  </div>

我可以使用 CSS 成功地为 ngRepeat div 错开动画:

.animate-stagger{
  animation-duration: 2s;
}

.animate-stagger.ng-enter-active {
     animation-name: slide;
     transform: scaleX(0);
}

.animate-stagger.ng-enter-stagger  {
  animation-delay: 1s;
  animation-duration: 0s;
}

我可以为子 div 设置动画,但它不会使用 CSS 错开:

.animate-child-stagger {
  animation-duration: 2s;
}

.animate-child-stagger.ng-enter-active div  {
     animation: slide 2s;
     transform: scaleX(0);
}

.animate-child-stagger.ng-enter-stagger div {
  animation-delay: 1s;
  animation-duration: 0s;
}

有没有一种方法可以使用 CSS 和 ngAnimate 错开子动画?

示例插件: http://plnkr.co/edit/08TviNqVUTkGCnLNDKdp?p=preview

最佳答案

我能够通过将动画延迟应用于父元素(即使它是动画的子元素)来完成这项工作。

.animate-stagger-child {
  animation-duration: 2s; 
}

.animate-stagger-child.ng-enter-active div  {
     animation: slide 2s;
     transform: scaleX(0);
}

.animate-stagger-child.ng-enter-stagger {
  animation-delay: 1s;
  animation-duration: 0s;
}

关于css - 不能错开 ngAnimate 子动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37373476/

相关文章:

javascript - 在 AngularJS 上读取 JSON

objective-c - 使用推送转换交换 NSView

animation - Threejs Mixer 未更新为 `setTime`

animation - 如何在没有 javascript 的情况下在 SVG 中重用动画标签

html - 包含图像时 Div 高度保持为零

css - 无法让 Bootstrap 网格在 Rails 应用程序中工作

javascript - 创建一个显示尺寸与其内容尺寸不同的 div

javascript - 如何将 ng-model 添加到运行时创建的 html 对象

html - 使用过多的 colspan 的潜在缺点是什么?

html - 如何在 Angular JS 应用程序中使用 ckeditor?