【问题标题】:Multiple animations in Raphael (move line and circle plus transform the circle)Raphael 中的多个动画(移动线和圆以及变换圆)
【发布时间】:2014-03-31 02:25:50
【问题描述】:

我有一个圆圈和一条路径(四条小线)。我制作了一组圆圈和路径(带线条)。现在我尝试移动组并(在移动时)变换圆(s3)。 有人知道为什么这不起作用吗?

var paper = Raphael(0, 0, 500, 500);

var circle = paper.circle(8, 8, 1).attr({ stroke: '#fff', fill: '#f00'});

var anim1 = Raphael.animation({ transform: "s3"}, 500);
circle.animate(anim1.repeat(Infinity));

var line = paper.path('M 0,8 l 5,0 M 8,0 l 0,5 M 11,8 l 5,0 M 8,11 l 0,5 z'); line.attr('stroke', 'red');

var group = paper.set(); group.push(circle, line);

var anim3 = Raphael.animation({ transform: "T 100, 100 R 360"}, 1500);
group.animateWith(circle, anim1, anim3.repeat(Infinity));

小提琴:http://jsfiddle.net/76CGE/

我怎样才能移动路径(带线)和圆圈,并且在它们移动的同时对圆圈进行变形?

【问题讨论】:

    标签: javascript animation svg raphael


    【解决方案1】:

    由于似乎不可能在 raphael 中同时运行多个动画,因此您可能不得不将动画切割成碎片。这不是一个优雅的解决方案,但结果可能是您想要实现的。

    小提琴:http://jsfiddle.net/75ZFU/

    var paper = Raphael(0, 0, 500, 500);
    var circle = paper.circle(8, 8, 1).attr({ stroke: '#fff', fill: '#f00' });
    
    var anim1 = Raphael.animation({ transform: "s3 T 33,33"}, 500, "linear", function() {         circle.transform("s1 T 33,33").animate(anim2)});
    var anim2 = Raphael.animation({ transform: "s3 T 66,66"}, 500, "linear", function() {     circle.transform("s1 T 66,66").animate(anim3)});  
    var anim3 = Raphael.animation({ transform: "s3 T 100,100"}, 500, "linear", function() { circle.transform("s1 T 0,0").animate(anim1)});
    circle.animate(anim1);
    
    var line = paper.path('M 0,8 l 5,0 M 8,0 l 0,5 M 11,8 l 5,0 M 8,11 l 0,5 z');
    line.attr('stroke', 'red');
    
    var anim4 = Raphael.animation({ transform: "T 33, 33 R 120"}, 500, "linear", function() { line.transform("T 33, 33 R 120").animateWith(circle, anim2, anim5)});
    var anim5 = Raphael.animation({ transform: "T 66, 66 R 240"}, 500, "linear", function() { line.transform("T 66, 66 R 240").animateWith(circle, anim3, anim6)});
    var anim6 = Raphael.animation({ transform: "T 100, 100 R 360"}, 500, "linear", function() { line.transform("T 0, 0 R 0").animateWith(circle, anim1, anim4)});
    line.animateWith(circle, anim1, anim4);
    

    【讨论】:

    • 谢谢! Bumber,它不能多个。问题是这只是一些小测试场景。真正的解决方案有一条不容易提前破解的路径。
    • 也许this stackoverflow 可能会有所帮助。沿路径的动画是使用 setInterval 独立完成的,翻译后的对象本身可以使用 .animate 进行动画处理。可能是。否则,缩放也需要在 setINterval 中完成。事实上,这将是更优雅的解决方案:-)
    猜你喜欢
    • 1970-01-01
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多