問題出在你的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;
}
同意,如果你使用'.icon刷新 - 動畫 - add',角將盡力檢測'add'動畫期間是無限的。所以'.icon-refresh-animate-add'永遠不會被刪除。如果沒有'add'類,'.icon-refresh-animate'將被直接添加和刪除。 – Daiwei
我有一種感覺,這很容易,非常感謝! – Curt