Animation delay ng-repeat

吃可爱长大的小学妹 提交于 2019-12-25 07:14:00

问题


I have this code with ng-repeat and delay in css:

<div class="card moveUp" ng-repeat="x in optionsCards" style="animation: moveUp 0.50s ease forwards;">

    <span class="fec">Updated Aug 29, 2016</span>

    <span class="title">Internet Banner Advertising…</span>

</div>

I need that the delay value in every item of ng-repeat , increase. For example:

First item: animation: moveUp 0.50s ease forwards Second item: animation: moveUp 0.60s ease forwards Third item: animation: moveUp 0.70s ease forwards

How can I make that ?

Thanks


回答1:


You can substitute 0.50s in style attribute with angular expression. A simple solution would be:

<div class="card moveUp" ng-repeat="x in optionsCards" style="animation: moveUp {{ (0.5 + 0.1 * $index) + 's' }} ease forwards;">

$index contains an index of current ng-repeat element so if you multiply it by 0.1 and add to base 0.5, each item will have delay 0.1s longer than its predecessor.




回答2:


You could use the ngStyle directive with $index.

See this working example with keyframes:

angular.module('MyApp', []);
.moveUp {
  position: relative;
}
@-webkit-keyframes moveUp {
  0% {
    top: 500px;
  }
  100% {
    top: 0px;
  }
}
@keyframes moveUp {
  0% {
    top: 500px;
  }
  100% {
    top: 0px;
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="MyApp">

  <div class="card moveUp" ng-repeat="x in [1,2,3,4,5,6] track by $index" ng-style="{'animation': 'moveUp ' + ($index / 2) + 's ease forwards'}">

    <span class="fec">Updated Aug 29, 2016</span>

    <span class="title">Internet Banner Advertising…</span>

  </div>

</div>

The result will give you 0.5s, 1s, 1.5s and so on...



来源:https://stackoverflow.com/questions/39399615/animation-delay-ng-repeat

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