我想在使用ng-repeat重複的自定義指令上使用ngAnimate。 如果我在簡單的html列表項上使用ng-repeat,那麼動畫工作得很好。但是,只要用自定義指令元素替換列表項,動畫就不會被觸發。ngAnimate - 在重複的自定義指令中未觸發動畫
我在想什麼/做錯了什麼?
碼(Plunker Demo):
HTML
<h3>Simple ng-repeat</h3>
<ul>
<li class="animate-repeat" ng-repeat="val in testValues">{{ val }}</li>
</ul>
<h3>ng-repeat on custom directive</h3>
<ul >
<animation-test class="animate-repeat" ng-repeat="val in testValues" test-val="val"></animation-test>
</ul>
的Javascript
var app = angular.module('application', ['ngAnimate']);
app.controller('mainController', [ '$scope', mainController]);
function mainController($scope){
// just for demo purposes
$scope.testValues = [];
$scope.addItem = function(){
var len = $scope.testValues.length;
$scope.testValues.unshift('Value #' + len);
};
$scope.removeItem = function(){
$scope.testValues.pop();
};
}
app.directive('animationTest', animationTest);
function animationTest(){
return {
template: ' <li> {{testVal}} </li> ',
scope: {
testVal: '<'
}
};
}
CSS(使用animate.css)
.animate-repeat.ng-enter {
animation: 0.5s slideInUp;
}
.animate-repeat.ng-leave,
.animate-repeat.ng-move {
animation: 0.5s slideOutDown;
}
@-webkit-keyframes slideInUp {
from {
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
visibility: visible;
}
to {
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
}
@keyframes slideInUp {
from {
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
visibility: visible;
}
to {
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
}
.slideInUp {
-webkit-animation-name: slideInUp;
animation-name: slideInUp;
}
@-webkit-keyframes slideOutDown {
from {
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
to {
visibility: hidden;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
}
}
@keyframes slideOutDown {
from {
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
to {
visibility: hidden;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
}
}
.slideOutDown {
-webkit-animation-name: slideOutDown;
animation-name: slideOutDown;
}
這並獲得成功,非常感謝你! – WiRo
沒問題。很高興我能幫上忙 :) – thepio