我正在制作像这样的D3可缩放圆形包装气泡布局: http://bl.ocks.org/mbostock/7607535
我理解了json并设法使用我自己的json数据。 但是我想通过jQuery为气泡添加交互性。
有些事情:
$(IdOfCurrentBubble).mouseover(function({
play sound (iDOfCurrentBubble.mp3);
doStuff;
doOtherStuff;
});
答案 0 :(得分:1)
为什么是jquery?使用d3
添加事件处理程序:
var circle = svg.selectAll("circle")
.data(nodes)
.enter().append("circle")
.attr("class", function(d) { return d.parent ? d.children ? "node" : "node node--leaf" : "node node--root"; })
.style("fill", function(d) { return d.children ? color(d.depth) : null; })
.on("click", function(d) { if (focus !== d) zoom(d), d3.event.stopPropagation(); })
.on("mouseover", function(d){ //<--here's your mouseover
console.log(d.name);
});
<强> EDITS 强>
抱歉,我错过了关于通过ID申请该功能的部分。
var circle = svg.selectAll("circle")
.data(nodes)
.enter().append("circle")
.attr("class", function(d) { return d.parent ? d.children ? "node" : "node node--leaf" : "node node--root"; })
.style("fill", function(d) { return d.children ? color(d.depth) : null; })
.on("click", function(d) { if (focus !== d) zoom(d), d3.event.stopPropagation(); })
d3.select("#IdOfCurrentBubble")
.on("mouseover", someFunc);
function someFunc(){
var myId = d3.select(this).attr('id');
// use myId here
}
编辑2
如果您希望mouseover
仅针对最低级别的孩子,请按类别定位:
d3.selectAll(".node--leaf")
.on("mouseover", someFunc);