我正在使用 ng-repeat 指令生成一些<rect>
带有<animate>
孩子的 s。
在页面加载时,动画被正确触发,一切都按预期发生。但是,当我添加一个新动画时<rect>
,动画不会发生。
以下代码片段演示了这种行为:
function Controller($scope) {
$scope.rects = [];
var spacing = 5;
var width = 10;
var height = 100;
var x = 10;
var y = 10;
$scope.newRect = function() {
$scope.rects.push({
x: x,
y: y,
width: width,
height: height
});
x += spacing + width;
};
for (var i = 0; i < 5; i++) {
$scope.newRect();
}
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app ng-controller="Controller">
<svg width="1000" height="200">
<rect ng-repeat="rect in rects" x="{{rect.x}}" y="{{rect.y}}" height="{{rect.height}}" width="{{rect.width}}">
<animate attributeName="y" from="{{rect.height}}" to="{{rect.y}}" dur="1s" repeatCount="1" />
<animate attributeName="height" from="0" to="{{rect.height}}" dur="1s" repeatCount="1" />
</rect>
</svg>
<button ng-click="newRect()">One more</button>
</div>
加载示例后,<rect>
将出现 4,动画从底部到顶部。但是,当按下“再一个”按钮时,<rect>
将添加新的而不带动画(在 Firefox 35 和 Chrome 38 上测试的行为)。
如何触发 new <rect>
s 的动画?