2014-10-31 137 views
2

即时制作游戏并尝试在最后显示高分。当前用户名应该用不同的颜色突出显示,但我无法使其正常工作。 当我试图改变字体大小为测试目的它虽然工作!更改createElementNS()后的字体颜色

var nameSpan = svgdoc.createElementNS("http://www.w3.org/2000/svg", "tspan"); 

nameSpan.setAttribute("x", 130); 
nameSpan.setAttribute("dy", 30); 

var nameTextNode = svgdoc.createTextNode(record.name); 

if (record.name == playerName){ 
    nameSpan.style.fontColor = "red"; // does not work 
    nameSpan.style.color = "blue"; // does not work 
    nameSpan.style.fontSize = "100px"; // works fine 
} 

nameSpan.appendChild(nameTextNode); 

我尝试了不同的方法来应用颜色(其中2个可以在上面看到),但它始终保持黑色。

回答

2

SVG文本未使用颜色着色。相反,它使用填充和描边,因此您可以分别为轮廓着色。更改为nameSpan.style.fill = "blue",它应该适合你。