我正在调用这样的动画:
document.getElementById('banner').className = "changeColorToIndigo";
然后我获得了CSS属性:
div.changeColorToIndigo {
animation-duration: 1s;
animation-name: changeColorToIndigo;
animation-fill-mode: forwards;
}
关键帧动画:
@keyframes changeColorToIndigo {
from {background-color: #00BBD2;}
to {background-color: #3F51B5;}
}
但是动画完成后动画会回到它的初始状态,为什么会这样?我已将填充模式设置为向前并指定to
(100%)属性。
答案 0 :(得分:1)
我已将您的代码放入Fiddle,对我来说效果很好
HTML
<div id="banner"></div>
CSS
div{
height: 40px;
width: 40px;
background-color: #00BBD2;
}
div.changeColorToIndigo {
animation-name: changeColorToIndigo;
animation-duration: 1s;
animation-fill-mode: forwards;
}
@keyframes changeColorToIndigo {
from {background-color: #00BBD2;}
to {background-color: #3F51B5;}
}
的jQuery
$(document).ready(function(){
$('#banner').addClass('changeColorToIndigo');
})