请看这个示例。
http://jsfiddle.net/dfabulich/ncbzz5zu/3/
<html>
<body>
<style>
.container {
position: relative;
width: 80%;
height: 100px;
border: 1px solid black;
}
@keyframes slide {
from { background-color: red; left: 0; }
to { background-color: blue; right: 0; }
}
.animated {
position: absolute;
width: 20%;
height: 100%;
top: 0;
background-color: red;
animation-duration: 3s;
animation-name: slide;
animation-iteration-count: infinite;
}
</style>
<div class=container>
<div class=animated>
</div></div>
期望结果:随着颜色从红色变成蓝色,红色矩形应该平滑地从左向右移动。
实际结果:在Chrome/Firefox中,红色矩形缓慢变色为紫色,然后瞬间从左到右跳跃,没有动画效果,最后又缓慢地从紫色变为蓝色。在Safari中,矩形出现在右侧并且未移动,同时从红色渐变到蓝色时有动画效果。
为什么会发生这种情况?我该如何解决?(需要在CSS中解决,不使用JS或jQuery。)