我正在探索 AngularJS 中的动画,但在让交错的 CSS 动画正常工作时遇到了问题。添加新项目时它工作正常,但是当同时删除多个项目时,项目是从集合内部而不是从后面删除。换句话说,这些项目的删除顺序与我期望的相反。
HTML:
<div ng-controller="CompaniesCtrl">
<h2>Companies</h2>
<button ng-click="add()">Add</button>
<button ng-click="remove()">Remove</button>
<ul>
<li class="company" ng-repeat="company in companies">
<div>
<h4>{{company.name}}</h4>
<p>{{company.description}}</p>
</div>
</li>
</ul>
</div>
JavaScript:
function CompaniesCtrl($scope) {
$scope.companies = [
{ name: "Company A", description: 'A software vendor' },
{ name: "Company B", description: 'Another software vendor' },
{ name: "Company C", description: 'A software consultancy shop' },
{ name: "Company D", description: 'Another software consultancy shop' }
];
$scope.add = function () {
$scope.companies.push({ name: "Another company", description: 'Another software consultancy shop' });
$scope.companies.push({ name: "Another company", description: 'Another software consultancy shop' });
$scope.companies.push({ name: "Another company", description: 'Another software consultancy shop' });
};
$scope.remove = function () {
$scope.companies.splice($scope.companies.length - 3, 3);
};
}
CSS:
.company {
background-color: red;
margin: 10px;
padding: 10px;
}
.company.ng-enter-stagger, .company.ng-leave-stagger, .repeat-animation.ng-move-stagger {
-webkit-transition-delay: 0.3s;
transition-delay: 0.3s;
-webkit-transition-duration: 0;
transition-duration: 0;
}
.company.ng-enter {
-webkit-transition:0.2s linear all;
transition:0.2s linear all;
opacity: 0;
-webkit-transform:scale(1.15)!important;
transform:scale(1.15)!important;
}
.company.ng-enter.ng-enter-active {
opacity: 1;
-webkit-transform:scale(1)!important;
transform:scale(1)!important;
}
.company.ng-leave {
-webkit-transition:0.1s linear all;
transition:0.1s linear all;
opacity: 1;
}
.company.ng-leave.ng-leave-active {
opacity: 0;
}
我在这里创建了一个记录问题的 JSFiddle:http: //jsfiddle.net/VNB7R/
这是一个已知问题还是我在我的 JS 代码或 CSS 中做错了什么?