javascript - SVG 中的字体图标在 IE 11 中不起作用

标签 javascript d3.js fonts internet-explorer-11

SVG 外部元素中的字体图标在 IE11 中不起作用。虽然它可以在 Chrome 和 Firefox 中运行。这是我的代码

var svg = d3.select('#item svg');

svg.append('circle')
    .attr('r', 50)
    .attr('cx',100)
    .attr('cy', 100)
    .style('fill', 'lightgray');

svg.append('svg:foreignObject')
            .attr('x', 100)
            .attr('y', 100)
            .append('xhtml:span')
            .attr('class', ' glyphicon glyphicon-glass')
            .style('fill', 'white'); 

如果您打开this fiddler在 IE 11 中,您将在圆圈上看不到任何图标。然而 html 图标(svg 之外)在 IE11 中工作正常。

提前致谢。

最佳答案

为什么不直接使用 <text>元素?

https://jsfiddle.net/vyz3dgff/2/

var svg = d3.select('#item svg');
svg.append('circle')
    .attr('r', 50)
    .attr('cx',100)
    .attr('cy', 100)
    .style('fill', 'lightgray');

svg.append('svg:text')
        .attr('x', 100)
        .attr('y', 100)
        .attr('class', 'glyphicon')    // note no glyph selection
        .attr('text-anchor', 'middle') // horizontal alignment
        .attr('dy', '0.5em')           // vertical alignment
        .style('font-size', '48px')
        .style('fill', 'white')
        .text("\ue001");               // glyph as defined in the font

关于javascript - SVG 中的字体图标在 IE 11 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38744662/

相关文章:

d3.js - dc.js pieChart 设置特定的 x 轴值

javascript - 为节点 dagre d3 添加颜色

fonts - 在 IIS 上仅为字体文件启用 CORS

android - 防止用户更改字体

javascript - 如何通过JS绘制的表格上的按钮删除行

javascript - 如何防止在解析完成之前更改路由?

javascript - 如何恢复到原始 CSS?

javascript - 用从 php 文件返回的 json 值替换固定的 json 变量

angular - 如何在 Angular 8 中使用本地字体系列?

javascript - 更改 NodeJS 定时器回调函数