AngularJS.de - Animations with ng-repeat
Example for AngularJS with ng-repeat and ng-animate.
by angularjs_de
HTML
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js"></script>
<button ng-click="replaceItem()">Go!</button>
<ul>
<li ng-repeat="item in items" ng-animate="'repeat'">{{item}}</li>
</ul>
CSS
.repeat-enter-setup, .repeat-leave-setup {
-webkit-transition:all linear 0.3s;
-moz-transition:all linear 0.3s;
-ms-transition:all linear 0.3s;
-o-transition:all linear 0.3s;
transition:all linear 0.3s;
}
.repeat-enter-setup { line-height:0; opacity:0; }
.repeat-enter-setup.repeat-enter-start { line-height:20px; opacity:1; }
.repeat-leave-setup { opacity:1; line-height:20px; }
.repeat-leave-setup.repeat-leave-start { opacity:0; line-height:0; }
JavaScript
function MainController($scope) {
$scope.items = [1,2,3,4,5,6,7,8,9];
$scope.replaceItem = function() {
$scope.items.shift();
$scope.items.push(Math.floor(Math.random()*1000000000));
};
}