【问题标题】:How to rotate an object back and forth around a specific point?如何围绕特定点来回旋转对象?
【发布时间】:2012-05-01 17:58:34
【问题描述】:

我正在使用 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);

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

【问题讨论】:

    标签: javascript animation raphael transform


    【解决方案1】:
    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);
    

    我还设置了一个working example on jsFiddle 来演示它是如何完成的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 2021-09-13
      相关资源
      最近更新 更多