如何围绕特定点来回旋转对象?

Hav*_*ons 5 javascript animation transform raphael

我正在使用Raphael JS试图围绕低于其中心点的点旋转图像形状.如何才能做到这一点?

我尝试了以下但它不起作用.

var playBBox = playButtonRef.getBBox();
var xPos = playBBox.x + playBBox.width/2;
var yPos = playBBox.y;
var animObject = Raphael.animation({
    transform: playButtonRef.attr("transform") + "R60," + (this.cx - 25) + "," + this.cy
}, 3000);?
animObject = animObject.repeat(10); 
playButtonRef.animate(animObject);
Run Code Online (Sandbox Code Playgroud)

我也在寻找一种方法将它旋转回原来的位置.如何让它追溯它的路径?

Eli*_*lka 3

  1. 要围绕指定点旋转,您可以使用已经定义的xPosyPos,并通过增加 Y 值来修改它们以引用中心下方的点。
  2. 要追踪其路径,您可以使用callback参数调用额外的动画调用,该调用会将形状重置为其原始位置。

以下是如何让它发挥作用:

var playBBox = playButtonRef.getBBox();
var xPos = playBBox.x + (playBBox.width / 2);
var yPos = playBBox.y + 25;

var animObject = Raphael.animation({
    transform: "R60," + xPos + "," + yPos
}, 3000, function() {
    playButtonRef.animate({
        transform: "R0," + xPos + "," + yPos
    }, 3000);
});
playButtonRef.animate(animObject);
Run Code Online (Sandbox Code Playgroud)

我还在jsFiddle 上设置了一个工作示例来演示它是如何完成的。