CSS关键帧动画返回初始状态

时间:2015-11-06 10:07:17

标签: css animation keyframe

我正在调用这样的动画:

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%)属性。

1 个答案:

答案 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');
})