【发布时间】:2017-01-18 12:20:40
【问题描述】:
我有以下代码:
我有两个小圆圈出现在大圆圈的鼠标悬停上。我面临的问题是-当我将鼠标移到较小的圆圈上时,它会消失,从堆栈溢出中发现添加pointer-events:none 将停止此操作。但我需要在这些圈子上绑定点击事件。这个问题有什么解决办法吗?
d3.selectAll(".node-hover-button").attr("opacity", 0);
d3.select("circle").on("mouseover", function() {
d3.select(this.parentNode).selectAll(".node-hover-button").attr("opacity", 1);
}).on("mouseout", function() {
d3.select(this.parentNode).selectAll(".node-hover-button").attr("opacity", 0);
});
//attach a click event on .node-hover-button.
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.7/d3.min.js"></script>
<svg>
<g transform="translate(100,50)">
<rect x="50" y="-30" width="50" height="60" id="yesDecision" class="hoverNodeundefined" style="fill: rgb(51, 110, 123);"></rect>
<text x="80" y="0" class="id ">Yes</text>
<circle class="node fixed" r="58" style="fill: rgb(30, 139, 195); stroke: rgb(21, 97, 136);" transform="scale(1.0)"></circle>
<text x="0" y="20" class="id">Segment</text>
<rect class="edit-event node-hover-button" x="-20" y="-70" height="29" width="29" rx="15" ry="15"></rect>
<rect class="delete-event node-hover-button" x="-54" y="-54" height="29" width="29" rx="15" ry="15"></rect>
</g>
</svg>
【问题讨论】:
-
只需在小圆圈上使用与大圆圈相同的鼠标悬停事件。即在鼠标悬停时显示(保持打开)2 个小圆圈
标签: javascript d3.js