推荐你使用 gsap 套件,用这个库做动画可以更加方便一些。
官网 http://greensock.com
安装 bower install gsap
这么理解吧,这是一个 CSSRuleList,在被你展开之前,CSSRuleList 的信息仅是一个指针,控制台并没有缓存到这个 List 的所有信息。
因此,当你展开之后,读取到的信息已经是修改后的了。
你可以做这样的一个测试,先 console.log 出来,不展开,然后进行修改,结果也是修改之后的信息!!
下面的回答有点跑题,但是可以实现改变动画效果的最终目的。
不能理解为何一定要修改@keyframes,而不直接改变 ClassName。
animation 的效果是可被覆盖的。
增加一个 ClassName 比修改样式表要方便多了!
<!DOCTYPE html>
<html>
<head>
<style>
.a
{
width:100px;
height:100px;
background:red;
position:relative;
-webkit-animation:mymove 5s infinite;
}
.b
{
-webkit-animation:mymove2 5s infinite;
}
@-webkit-keyframes mymove2
{
from {left:0px;}
to {left:200px;}
}
@-webkit-keyframes mymove /* Safari and Chrome */
{
from {top:0px;}
to {top:200px;}
}
</style>
</head>
<body>
<button onclick="document.getElementById('a').className+=' b'">变换动画</button>
<p id="a" class="a"></p>
</body>
</html>