【问题标题】:Animate a Raphael element and its set of glow paths为 Raphael 元素及其一组发光路径设置动画
【发布时间】:2013-11-05 09:31:44
【问题描述】:

这个answer has been accepted 但它不起作用,因为glowSet.animate({cx: 100}) 不会像圆圈一样移动光晕。此外,要为焕发集路径对象设置动画,您需要应用 a transformation, something like this,但一个简单的移动转换会将辉光路径缩小到 0。

目前的方法是js fiddle,还是有更聪明的方法来实现同样的目标?:

paper = Raphael(0, 0, 200, 200);
circle = paper.circle(10, 10, 10);
glow = circle.glow();
glow.push(circle);
all = glow;
all.attr("stroke", "#f00");

// Animation
delay = 300
speed = 1000

// Will only animate the glow paths and not the circle
// Also shrinks the glow paths to nothing.
_transformedPath = Raphael.transformPath('M100 100');
animGlow = Raphael.animation({path: _transformedPath}, speed);
all.animate(animGlow.delay(delay + 200));

//We shouldn't want or need to do this.  You can apply an
//element.matrix.translate(x, y), followed by a //element.transform(element.matrix.toTransformString()) for 
//each of the elements in the glowSet
anim = Raphael.animation({cx: 100, cy: 100}, speed);
circle.animate(anim.delay(delay));

【问题讨论】:

标签: animation raphael glow svg-animate


【解决方案1】:

对于动画,您只需要使用translate 而不是matrix,对于transform

// Animation
delay = 300
speed = 1000

_transformedPath = Raphael.transformPath('t100 100');
animGlow = Raphael.animation({transform: _transformedPath}, speed, '<>');
all.animate(animGlow.delay(delay));

【讨论】:

  • 请注意,如果你想使用回调,你应该把它包裹在类似underscore's _.once的东西中,否则它会为all中的每个元素触发,在这个例子中是7次。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-05
  • 2014-03-29
  • 2015-06-05
  • 2014-11-22
  • 1970-01-01
相关资源
最近更新 更多