RaphaelJs 饼图悬停动画
我正在自定义下面链接的拉斐尔网站上给出的饼图 http://raphaeljs.com/pie.html
此图表显示悬停切片时的动画,此动画只需将切片扩展一点,
我想要的是将切片与我使用以下代码行的转换属性播放的图表分开
,但无法按照我的意愿制作。
p.mouseover(function () {
var xis= p.getBBox(true);
p.stop().animate({transform: "s1.1 1.1 "+ cx + " " + cy }, ms, "linear");
txt.stop().animate({opacity: 1}, ms, "linear");
}).mouseout(function () {
p.stop().animate({transform: ""}, ms, "linear");
txt.stop().animate({opacity: 0}, ms);
});
更改第 3 行的 cx 和 cy 实际上以相同的方式固定了每个切片的动画,也就是说,在悬停时每个切片都会不断改变位置。
http://imageshack.us/photo/my-images/690/sliced1。 png
有人请帮我解决这个问题
i am customizing the pie chart given on the raphael site below link
http://raphaeljs.com/pie.html
this chart shows animation when hover a slice, this animation simply expand the slice a little
what i want is to separate the slice from the chart
i played with the transform property of following lines of code but could not make it as i want.
p.mouseover(function () {
var xis= p.getBBox(true);
p.stop().animate({transform: "s1.1 1.1 "+ cx + " " + cy }, ms, "linear");
txt.stop().animate({opacity: 1}, ms, "linear");
}).mouseout(function () {
p.stop().animate({transform: ""}, ms, "linear");
txt.stop().animate({opacity: 0}, ms);
});
Changing the line 3's cx and cy actually fixed the animation for every slice in the same manner, that is, on hover every slice will change the position constantly.
http://imageshack.us/photo/my-images/690/sliced1.png
anyone please help me out to solve this problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解你的问题,那么当有人将鼠标悬停在切片上时,你希望切片与饼图完全断开连接。
为此,您需要平移该段,这样您就可以将 SVG 对象沿给定方向(即 x、y 坐标)移动。我不是 SVG 专业人士,所以我建议您自己研究一下它的完整功能;无论如何,要使用 Raphael 执行这些类型的操作,您可以使用
Element.transform
,或者可以在
animate
调用中提供变换值。第二个是您提供的示例中发生的情况,除了使用比例转换之外,如
transform 中的前导
s
所示:“s1.1 1.1.。,您想要使用移动对象但不会使其变大的平移 - 它使用
t
。在这里 将执行此操作:
在示例中,
distance
指切片应移动多远(因此请随意调整它),xShiftTo
和yShiftTo
计算 x、y 值对象应该相对于它们当前所在的位置移动,请注意,这有点复杂 - 您需要计算出与饼图中心相距给定角度的 x、y 值。文本的定位也执行类似的操作。这个,所以我只是从那里得到了所需的数学知识。另外,我只保留了反弹动画,但您可以将其更改为线性或任何您想要的。希望有帮助。If I understand your question correctly, you want the slice to completely disconnect from the pie chart when somebody hovers over it.
To do this, you want to translate the segment, which allows you to move an SVG object in a given direction, toward x, y co-ordinates. I'm no SVG pro, so I'd suggest taking a look into the full functionality of this yourself; regardless, to do these types of operations with Raphael, you can use the
Element.transform
, or can provide transform values in ananimate
call.The second of these is what is happening in the example you provided, except a scale transformation is being used, as indicated by the leading
s
intransform: "s1.1 1.1.
. A scale will make the object bigger.Here, you want to use a translation which moves the object but doesn't make it bigger - it uses a
t
.Here is a slightly edited block of code that will do this:
In the example,
distance
refers to how far the slice should move away (so feel free to adjust this),xShiftTo
andyShiftTo
calculate the x, y values that the object should shift by, relative to where they currently are. Note that this is a little complicated - you need to figure out the x, y values at a given angle away from the pie centre. The positioning of the text also does something like this, so I just took the required maths from there. Also, I just left thebounce
animation, but you can change that tolinear
or whatever you want. Hope that helps.您可能应该使用 Raphael 中内置的 .hover。请参阅此处的文档:http://raphaeljs.com/reference.html#Element.hover
通过奥利的例子,我能够弄清楚大部分基本的动画原理。作为一个数学大师,这个例子有很多空白需要填补。这是一个功能齐全的版本(经过测试)。享受!
You should probably be using .hover which is built into Raphael. See documentation here: http://raphaeljs.com/reference.html#Element.hover
Working off of Oli's example I was able to figure out most of the basic animation principles. Not being a math guru there were a lot of gaps to fill in for the example. Here is a fully functioning version (tested). Enjoy!