How to delay ngAnimate in ngRepeat

doorman picture doorman · Apr 8, 2013 · Viewed 20.1k times · Source

When using ngAnimate to fade in each item in ngRepeat, currently all items fade in at the same time. Is it possible for each item to fade in after the previous item has faded to e.g. 50% resulting in a cascading effect?

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

Using ngAnimate it would be nice if it would be possible to delay the animation of each item e.g. like this:

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

Is there a way to solve this?

Thanks!

Added to GitHub https://github.com/angular/angular.js/issues/2460

Answer

matsko picture matsko · Nov 8, 2013

This is now supported natively with 1.2: https://docs.angularjs.org/api/ngAnimate#css-staggering-animations

To make use of it, use the ng-enter-stagger selector in your CSS, like so:

css:

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

sass (if in use):

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

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