我有一个要求,其中一部分代码构建了一堆:
$scope.values = items;
另一部分代码会监视此集合:
scope.$watchCollection('values', function(values) {
if(Array.isArray(values)) {
//only if it's an array, draw and watch all its items for changes
draw(values);
for(var key in values) {
if(values.hasOwnProperty(key)) {
scope.$watch("values['" + key + "']", function(val, oldVal) {
updateValue(val.id);
}, true); }
}
}
});
updateValue函数负责动画:
var updateValue = function(id) {
//when an item changes, trigger the change animation
var sectElement = svg.select(".arc-section-" + id);
//go to highlighted mode
sectElement.transition()
.duration(changeValueTransitionSpeed)
.call(drawSectionHighlighted);
//after highlighted mode transition is done, go back to normal mode
sectElement
.transition()
.delay(changeValueTransitionSpeed)
.duration(changeValueTransitionSpeed)
.call(drawSection);
}
一旦值集合被填充,updateValue将立即执行并开始动画。当新事件到来时,动画每3秒开始一次。我想控制动画的时间,这可以根据参数动态决定。
P.S我已经尝试过setTimeout()和setInterval()。