简体   繁体   English

如何为raphael.js动画设置旋转原点?

[英]How do I set rotation origin for a raphael.js animation?

I have 8 paths generated thusly: 我这样生成了8条路径:

for (i = 0 ; i<8; i++){
    slices[i] = card.path("M320 120 L320 215").attr({"stroke" : "#00A5Df",
            "stroke-width" : 10});
}

I want them to rotate from origin of M320 120(start of the line) in a clockwise direction to produce a 'pie' effect: 我希望它们以顺时针方向从M320 120的原点(线的起点)旋转,以产生“饼”效果:

for (i = 0 ; i<8; i++){
    slices[i].animate({transform :"r"+45*(i+1)+""},(200*i));
}

Instead the origin used is in the centre of the line. 相反,使用的原点位于线的中心。 I've tried formatting the string like 我已经尝试过格式化字符串了

"r45 cx320 cy120"

and other combinations but the values are always ignored. 和其他组合,但总是忽略值。

edit: here is a fiddle which more clearly highlights my problem: http://jsfiddle.net/vMRdj/ 编辑:这是一个更清楚地突出我的问题的小提琴: http//jsfiddle.net/vMRdj/

You almost nailed it. 你几乎钉了它。 The important thing is to use the absolute version of the rotate directive ("R" instead of "r") and to specific the origin explicitly, using the format "R(degree) (origin-x),(origin-y)". 重要的是使用旋转指令的绝对版本(“R”而不是“r”)并使用格式“R(度)(origin-x),(origin-y)”明确指定原点。

Here's the code: 这是代码:

for (i = 0 ; i<8; i++){
    slices[i].animate({transform : ["R", 45*(i+1), 320, 120 ] }, i * 125 );
}

And the fiddle: http://jsfiddle.net/kevindivdbyzero/F4xhh/ 小提琴: http//jsfiddle.net/kevindivdbyzero/F4xhh/

Don't forget that you can pass transform and paths as arrays -- it makes it a lot easy to structure your parameters if you don't have to worry about concatenating comma separators between arguments. 不要忘记您可以将transform和paths作为数组传递 - 如果您不必担心在参数之间连接逗号分隔符,则可以很容易地构造参数。

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

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