Angularjs 递归触发$animate.addClass动画
嗨,我正在尝试为我的项目设置一个循环动画。我正在尝试使用$animate设置递归触发的动画。在我的一个指令的link函数中,它看起来是这样的:Angularjs 递归触发$animate.addClass动画,angularjs,css,ng-animate,animate.css,Angularjs,Css,Ng Animate,Animate.css,嗨,我正在尝试为我的项目设置一个循环动画。我正在尝试使用$animate设置递归触发的动画。在我的一个指令的link函数中,它看起来是这样的: function startLoopAnimation(count) { if(loopSkip === false) { animateLoop().then(function() { count--;
function startLoopAnimation(count) {
if(loopSkip === false) {
animateLoop().then(function() {
count--;
if(count > 0) {
startLoopAnimation(count);
}
});
}
function animateLoop() {
return $animate.addClass(element,
'wobble ' +
'linear' +
' duration-' + scope.config.animation.loop.duration * 10
);
}
}
调用该函数,但不会再次触发动画。
设置这样的异步触发动画的最佳方法是什么
这也必须适用于android上的旧版本,所以性能是关键。此外,使用“无限”动画迭代计数也不是一个选项
更新:我为这个特定的案例提供了解决方案,但是我仍然想知道为什么这样做不起作用,以及我如何使它起作用。我通过简化代码来修复代码。只要我能够访问循环迭代的数量,我就可以设置“动画迭代计数”来循环动画正确的次数
function animateLoop(loopCount) {
return $animate.addClass(element,
scope.config.animation.loop.animation + ' ' +
scope.config.animation.loop.timingFunction +
' duration-' +
scope.config.animation.loop.duration * 10 +
' iteration-count-' + loopCount
);
}
我还使用较少的循环来生成迭代类,就像我在duration中所做的那样:
.iterationLoop(@counter: 100) when (@counter > 0) {
.iteration-count-@{counter} {
-webkit-animation-iteration-count: @counter;
animation-iteration-count: @counter;
}
.iterationLoop((@counter - 1));
}
.iterationLoop();