问题出在你的 CSS 中。
你不需要'.icon-refresh-animate-add'。
使用这个 CSS 类:
.icon-refresh-animate {
animation-name: rotateThis;
animation-duration: .5s;
animation-iteration-count: infinite;
animation-timing-function: linear;
-webkit-animation-name: rotateThis;
-moz-animation-name: rotateThis;
-webkit-animation-duration: .5s;
-moz-animation-duration: .5s;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-timing-function: linear;
}
这是您的动画添加的副本。
说明: ngClass 正在打开和关闭 .icon-refresh-animate 类。因此,当状态为真时,应用类并且动画永远循环。当状态为 false 时,css 类被删除,因此根本没有动画。所以这段代码为你完成了所有的工作
ng-class="{'icon-refresh-animate':refreshing}"
这是完整的 CSS:
@keyframes rotateThis {
from {
transform: scale(1) rotate(0deg);
}
to {
transform: scale(1) rotate(360deg);
}
}
@-webkit-keyframes rotateThis {
from {
-webkit-transform: scale(1) rotate(0deg);
}
to {
-webkit-transform: scale(1) rotate(360deg);
}
}
.icon-refresh-animate {
animation-name: rotateThis;
animation-duration: .5s;
animation-iteration-count: infinite;
animation-timing-function: linear;
-webkit-animation-name: rotateThis;
-moz-animation-name: rotateThis;
-webkit-animation-duration: .5s;
-moz-animation-duration: .5s;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-timing-function: linear;
}