【问题标题】:How to delay ngAnimate in ngRepeat如何在 ngRepeat 中延迟 ngAnimate
【发布时间】:2014-08-13 16:49:53
【问题描述】:

当使用 ngAnimate 淡入 ngRepeat 中的每个项目时,当前所有项目同时淡入。在上一个项目褪色到例如后,每个项目是否有可能淡入? 50% 导致级联效应?

<ul>
   <li ng-repeat="phone in phones" ng-animate="{enter: 'phone-fade-enter'}">
     <img src="{{phone.img}}"> {{phone.name}}
   </li>
</ul>

如果可以延迟每个项目的动画,例如使用 ngAnimate,那就太好了。像这样:

<li ng-repeat="phone in phones" ng-animate="{enter: 'phone-enter', delay: 500}">

有没有办法解决这个问题?

谢谢!

已添加到 GitHub https://github.com/angular/angular.js/issues/2460

【问题讨论】:

  • 你能更具体地说明你想做什么吗?
  • 我重新提出了这个问题...
  • 这更清楚了 - 感谢您的改写。不幸的是,我认为 ngAnimate 目前无法做到这一点。 ngAnimate 使用 CSS 过渡并根据事件使用类名触发它们。当 ngRepeat 首次运行时,所有这些现有项目基本上同时具有它们的事件。不过我会考虑更多...
  • 好问题:如果你得到答案,请联系我,我正在制作一个带有角度动画的网站帮助:AngularJS Animations

标签: angularjs angularjs-ng-repeat ng-animate


【解决方案1】:

现在 1.2 原生支持此功能:https://docs.angularjs.org/api/ngAnimate#css-staggering-animations

要使用它,请在 CSS 中使用 ng-enter-stagger 选择器,如下所示:

css:

.animated.ng-enter-stagger {
  transition-delay: 0.3s;
  animation-delay: 0.3s;
}

sass(如果正在使用):

=stagger($delay)
  &-stagger
    transition-delay: $delay
    animation-delay: $delay

.animated
  &.ng-enter
    +stagger(0.3s)

【讨论】:

    【解决方案2】:

    您可以通过在重复元素上设置过渡延迟样式来获得此效果。 (需要 v1.1.5)

    <li ng-repeat="phone in phones" ng-animate="{enter: 'phone-enter'}" style="transition-delay: {{$index * 500}}ms">
    

    您必须在 CSS 中单独设置过渡属性,否则内联样式将覆盖整个过渡:

    .phone-enter {
      opacity:0;
      -webkit-transition-property: all;
      -webkit-transition-timing-function: ease-out-cubic;
      -webkit-transition-duration: 400ms;
    }
    .phone-enter.phone-enter-active {
      opacity: 1;
    }
    

    这是由 heyotwell 创建的 fork of the example

    【讨论】:

      猜你喜欢
      • 2016-09-04
      • 2016-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-27
      • 2015-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多