简体   繁体   English

如何在Raphael中将停止时的动画重置为其初始状态?

[英]How to reset an animation on stop to its initial state in Raphael?

What I want to do is when I stop an animation to reset the initial state of the animated object. 我想做的是当我停止动画以重置动画对象的初始状态时。 I want to do that because when I stop it now ( Element.stop([anim]) ) it freezes in its current point (lets say half tranperant) and when I play it again the animation starts to repeat from this place not from the beginning. 我想这样做是因为当我现在停止它( Element.stop([anim]) )时,它会冻结在其当前点(让我说是半透明的),并且当我再次播放它时,动画将从该位置开始而不是从该位置开始重复开始。

Here is my animation Raphael.animation({opacity: 0}, 500, "<>").repeat(Infinity) . 这是我的动画Raphael.animation({opacity: 0}, 500, "<>").repeat(Infinity)

I asked this question in the Raphael newsgroup 3 weeks ago but I didn't receive any answer. 3周前,我在Raphael新闻组中问了这个问题,但没有得到任何答案。

Thanks, bozhidarc 谢谢,bozhidarc

I'm not suggesting it's the most elegant, but in the past I've done things like this simply by adding a couple of extra attributes to the element when you create it. 我并不是说它是最优雅的,但是在过去,我只是通过在创建元素时向元素添加几个额外的属性来做到这一点。 In this case, I'd just add a baseAttrs attribute, which holds the original object of settings: 在这种情况下,我只需要添加一个baseAttrs属性,即可保存设置的原始对象:

    var paper = Raphael('canvas', 500, 500);

    var circle = paper.circle(320, 240, 60);
    circle.baseAttrs = {fill:'yellow'}; // add to the elem
    circle.attr(circle.baseAttrs);

    circle.animate({fill: "blue"}, 1000,
                   function(){
                       this.attr(this.baseAttrs);
                   });

In the above example, the callback from the animation sets the attributes of the circle to the baseAttrs value of the element when the animation is complete. 在上面的示例中,动画完成时,来自动画的回调将圆的属性设置为元素的baseAttrs值。 The baseAttrs will always be held with the circle, regardless of what happens to it. 不管发生了什么, baseAttrs始终与圆保持在一起。 http://jsfiddle.net/UVPeh/ http://jsfiddle.net/UVPeh/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM