javascript - SVG 文本路径在 IE 中无法正常工作

标签 javascript html css svg d3.js

我正在制作一个 SVG,它的文本沿着圆形线路径。

文本在 Firefox 和 Chrome 中看起来不错,但在 IE11 中看起来不正确。有时只出现文本路径上的第一个字母。

这是 the fiddle .

     d3.select("#svg")
.append("path")
  .attr("id", "path1")
  .attr("d", "M 0,-1   C 0.5523, -1   1, -0.5523    1,0  C 1, 0.5523    0.5523, 1     0,1  C -0.5523, 1   -1, 0.5523    -1,0         C -1, -0.5523  -0.5523, -1   0,-1")
  .attr("transform", "scale(50, 50) translate(5,5)");


  d3.select("#svg")
  .append("text")
  .append("textPath")
  .attr("xlink:href", "#path1")
  .style("font-size", "10px")
  .text("hello radial world")
  .attr("fill", "blue")

最佳答案

我最终弄明白了这一点。

这是与 IE、Firefox 和 Chrome 兼容的 SVG 中圆形路径外部文本的成功公式!

var size = 50; // radius of ring
var centerX = 100;  // center x
var centerY = 100;  // center y

d3.select("#myDiv")
  .append("path")
.attr("id", "path1")
  .attr("d", "m "+centerX+", "+centerY+" a -"+size+",-"+size+" 1 1,1 "+size*2+",0 a -"+size+",-"+size+" 1 1,1 -"+size*2+",0")
 // do not use transform scale with text paths, IE does not like it! Define variables like this.

  d3.select("#myDiv")
    .append("text")
    .append("textPath")
    .attr("xlink:href", "#path1")
    .style("font-size", "10px")
    .style('letter-spacing','0px')
    .text("hello radial world")
    .attr("fill", "blue")

关于javascript - SVG 文本路径在 IE 中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24085109/

相关文章:

javascript - 如何使用 JavaScript 拆分逗号分隔的字符串并在循环中处理

javascript - 如何通过 Angular 4 中的 App Component 访问私有(private)属性?

javascript - 将一个 div 元素包含在另一个 div 元素中会破坏视差效果

javascript - 如何将排序和匹配谷歌表格公式转换为应用程序脚本/javascript?

javascript - 实现 Knockout.js 破坏性 foreach 循环

javascript - 尝试将元素 ID 转换为 jQuery 中的类选择器

html - 如何创建圆形搜索框

html - 如何缩进元素符号中的列表项?

jquery - 我可以将Class直接添加到容器中的img标签吗?

jquery - 如何使用 jQuery 的 css 将 div 背景颜色设置为 'none'?