gpt4 book ai didi

javascript - 拉斐尔 JS 派 : Add ID to path slices

转载 作者:行者123 更新时间:2023-11-29 09:58:55 26 4
gpt4 key购买 nike

我已经在 Raphael Google Groups 上看到过这个问题,但经过数小时的搜索后,在这里以及 Google 上,我似乎找不到解决方案。

我只是希望能够使用 jQuery 定位我的饼图(svg 路径)切片,但我无法弄清楚如何将自定义 ID 添加到路径标签 - 默认情况下没有 ID 属性:

<path fill="#764c29" stroke="none" d="M350,350L350.6911881148345,94.00093308961084A256,256,0,0,1,561.8463375189659,206.2741175716762Z" style="stroke-width: 1; stroke-linejoin: round;" stroke-width="1" stroke-linejoin="round"/>

理想的情况是这样的:

<path **id="my_id"** fill="#764c29" stroke="none" d="M350,350L350.6911881148345,94.00093308961084A256,256,0,0,1,561.8463375189659,206.2741175716762Z" style="stroke-width: 1; stroke-linejoin: round;" stroke-width="1" stroke-linejoin="round"/>

有人知道如何实现吗?

这是我用来创建饼图的代码:

window.onload = function () {
var r = Raphael("holder");


var pie = r.g.piechart(350, 350, 256, [56, 104, 158, 23, 15, 6]);

pie.hover(function () {
this.sector.stop();
this.sector.animate({scale: [1.1, 1.1, this.cx, this.cy]}, 500, "bounce");

}, function () {
this.sector.animate({scale: [1, 1, this.cx, this.cy]}, 500, "bounce");
});

};

基本上,我需要能够执行此操作的原因是,我可以创建一些单独的 anchor 触发器来执行上面显示的缩放动画。

非常感谢任何帮助。

最佳答案

饼图对象提供了 3 种到达扇区的方法。

1) 每个函数

pie.each(function(sector, cover, i) {
sector.attr({/*...*/}); //raphael
$(sector.node).foo(); //jquery
});

2) 系列对象(用于样式化和转换)

var i = 0; // 0 = 56, 1 = 104, 2 = 158 …

//raphael way to hide the first sector
pie.series.items[i].attr({ opacity : 0 });

//jquery way to hide the first sector
$(pie.series.items[i].node).hide();

其中 i 是您的数据数组的索引

演示:http://jsbin.com/eriqa5/2/edit

3) 覆盖对象(用于鼠标和触摸事件)

//raphael way to hover the first sector
pie.covers.items[0].hover(...);

//jquery way to hover the first sector
$(pie.covers.items[0].node).hover(...);

演示:http://jsbin.com/eriqa5/4/edit

关于javascript - 拉斐尔 JS 派 : Add ID to path slices,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5789832/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com