How to delay ngAnimate in ngRepeat

亡梦爱人 提交于 2019-12-02 16:19:43
matsko

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)

You can get this effect by setting the transition-delay style on the repeated element. (Requires v1.1.5)

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

You'll have to set your transition properties separately in your CSS, otherwise the inline style will overwrite the entire transition:

.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;
}

Here is a fork of the example created by heyotwell.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!