2016-08-03 89 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