简体   繁体   English

为什么SVG文本无法选择?

[英]Why svg text is unselectable?

I'm trying to make selectable tooltip in D3.js 我正在尝试在D3.js中选择工具提示

here is code: 这是代码:

var tooltip = obj.svg
  .append('g')
  .append('text')
  .attr("id", "tooltip")
  .text( "SPICE")
  .attr("font-family", "sans-serif")
  .attr("font-size", "20px")
  .attr("fill", "red")
  .style("opacity", .0);

... ...

.on("click", function (d) {
        d3.selectAll("#tooltip").transition()
        .style("opacity", (obj.tooltipVisible && obj.tooltipId === d.id) ? 0.0 : 1)

And in browser as a result I have following element (I have no any css for it either): 结果,在浏览器中,我有以下元素(我也没有任何CSS):

<g><text id="tooltip" font-family="sans-serif" font-size="20px" fill="red" x="35" y="11.538461538490488" style="opacity: 1;">SPICE</text></g>

And the problem is that this text is unselectable, through pointer changes on text hovering. 问题是,通过悬停文本时指针的更改,此文本是不可选择的。

So how to make this text element selectable by mouse? 那么如何使该文本元素可用鼠标选择呢?

If it makes sense - whole svg picture is here - you can see word SPICE on the top left, it's unselectable, I suppose text on the background prevents current text selection: 如果有道理-整个svg图片在这里-您会在左上角看到单词SPICE,它是不可选择的,我想背景上的文本会阻止当前的文本选择: 在此处输入图片说明

I have no problem selecting this text, but the location of the g is probably inside a translated g . 选择此文本我没有问题,但是g的位置可能在已翻译的g

Do you have some kind of overlay on the graph? 您在图形上有某种叠加层吗?

Make a very simple example like this. 做一个非常简单的例子,像这样。

 <svg width="200" height="200"> <g><text id="tooltip" font-family="sans-serif" font-size="20px" fill="red" x="35" y="11.538461538490488" style="opacity: 1;">SPICE</text></g> </svg> 

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

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