CSS 关键帧动画回到初始状态
CSS Keyframes animation go back to initial state
我正在调用这样的动画:
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%) 属性.
我已将您的代码放在 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');
})
我正在调用这样的动画:
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%) 属性.
我已将您的代码放在 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');
})