我有这段代码,我使用 20 条路径制作了一个角色并将其放入一个集合中。现在,当我设置动画时,第一个转换运行顺利,第二个动画卡顿,第三个动画没有按预期发生,第四个动画杀死了我的电脑,浏览器挂起,在任务管理器中我可以看到它消耗高达 70% 的 CPU。我怎样才能避免这种情况并释放资源,以便所有动画顺利运行。
*我必须对那个角色执行 10 个简单的 y 轴变换动画。
window.onload = function(){
var paper = Raphael(0,0,400,400);
var character = paper.set();
paper.setStart();
var attr = {fill:'red',stroke:'none'};
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var shape = paper.rect(100,100,10,20).attr(attr);
var character = paper.setFinish();
character.transform("t0,200")
//1st animation..
var chartrnsfrm = Raphael.animation({
transform:'...t0,-48'
},1000,"easeout",function(){
character.animate(chartrnsfrm1.delay(2000))
});
character.animate(chartrnsfrm.delay(2000));
//2nd animation..
var chartrnsfrm1 = Raphael.animation({
transform:'...t0,-48'
},1000,"easeout",function(){
character.animate(chartrnsfrm2.delay(2000))
});
//3rd animation..
var chartrnsfrm2 = Raphael.animation({
transform:'...t0,-48'
},1000,"easeout",function(){
character.animate(chartrnsfrm3.delay(2000))
});
//4th animation..
var chartrnsfrm3 = Raphael.animation({
transform:'...t0,-48'
},1000,"easeout");
}