我在AngularJS中探索動畫,並遇到了一個讓交錯CSS動畫工作的問題。當添加新項目時,它可以正常工作,但是當同時刪除多個項目時,項目將從集合內移除而不是從後移除。換句話說,這些項目是以我期望的相反順序刪除的。如何在AngularJS中使用ng-leave-stagger動畫
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/
是THI是一個已知的問題,或者我在我的JS代碼或CSS中做錯了什麼?
超時的想法不能很好地工作。其中提到的問題很明顯的一種情況是應用ng-repeat過濾器。在這種情況下,我不負責顯示/隱藏物品。 –