2016-08-03 92 views
0

SVG外来元素中的字体图标在IE11中不起作用。尽管它适用于Chrome和Firefox。这里是我的代码SVG中的字体图标在IE中不起作用11

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'); 

如果您在IE中打开11 this fiddler,你会看到在圈子没有图标。然而,html图标(在svg之外)在IE11中工作正常。

在此先感谢。

+0

IE不支持foreignObject标签。 –

回答

3

为什么不只是使用<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 
+0

非常感谢。它在IE中工作。顺便说一句,我如何在http://getbootstrap.com/components/中的其他图标找到文本'\ ue001'? – KhanSharp

+1

按照您在小提琴中所做的测试图标,然后检查它(右键单击它,选择相关选项),您应该在CSS中找到“content:\ e001”或类似内容。把它用在'.text()'中,但是注意你需要添加一个'u',所以'\ e001'变成'\ ue001'。 –

+0

完美。你是生命的救星 – KhanSharp