Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 递归触发$animate.addClass动画_Angularjs_Css_Ng Animate_Animate.css - Fatal编程技术网

Angularjs 递归触发$animate.addClass动画

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--;

嗨,我正在尝试为我的项目设置一个循环动画。我正在尝试使用$animate设置递归触发的动画。在我的一个指令的link函数中,它看起来是这样的:

            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();