2017-02-17 39 views
0

我是angularjs的新手,想要对每个ng-repeat元素应用500ms的延迟。下面的plunker中的代码是我正在寻找的确切的东西,但它不适用于最新版本的角色js(1.4.8)。以下网站还介绍了如何应用延迟,但有点混淆,关于add-active和-remove。如何应用延迟显示ng-repeat元素

这里是HTML,CSS和角代码

<script> 
    var m = angular.module('App', []); 

    m.controller('ExampleCtrl', function($scope) { 
     $scope.items = []; 

     $scope.addItems = function() { 
      $scope.items = [ 
      {name: "Apple"}, 
      {name: "Orange"}, 
      {name: "Banana"}, 
      {name: "Lemon"}, 
      {name: "Lime"}, 
      {name: "Melon"}, 
      {name: "Tangerine"} 
      ]; 
     } 
    }); 

</script> 

ul { 
     list-style-type: none; 
     position:relative; 
    } 

    li { 
     background-color:#e3e3e3; 
     color: #666; 
     font-family:Arial; 
     padding:1em; 
     margin:0 5px 5px 5px; 
     text-align: center; 
     text-transform: uppercase; 
    } 

    .insert-enter { 
     -webkit-transform:scale(0); 
     -webkit-transition-property: all; 
     -webkit-transition-timing-function: ease-out-cubic; 
     -webkit-transition-duration: 400ms; 
    } 
    .insert-enter.insert-enter-active { 
     -webkit-transform:scale(1); 
    } 

</style> 

<ul> 
     <li ng-repeat="item in items" 
      ng-animate="{enter:'insert-enter'}" 
      style="-webkit-transition-delay:{{$index * 500}}ms" 
     > 
      {{item.name}} 
     </li> 
    </ul> 

Punker Example

website about ng-repeat classes

回答

0

这是你的代码的工作演示https://plnkr.co/edit/LR9yadLEQySdQjTr6jg5?p=preview

我改变的事物:

  • 包括ngAnimate模块var m = angular.module('App', ['ngAnimate']);
  • 加在你的HTML代码.insert-enter.ng-enter
  • 更名.insert-enter.insert-enter-active.ng-enter.ng-enter-active
  • 按钮 <button ng-click="addItems()">Add Items</button>
  • 在HTML中包含的角动画库https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular-animate.js
  • 删除ng-animate="{enter:'insert-enter'}"
  • 更名
+0

谢谢你的帮助和节省我的时间:) –

+0

很高兴我能帮忙! – linktoahref

2

我认为你需要包括你的角模块中ngAnimate依赖性,还包括ngAnimate库在您的index.html文件

+0

我加了depe代码的问题和库,但它仍然无法正常工作。 –