我有这样的SVG行变量,像这样:SVG:线条颜色
var c_line = function (x1, y1, x2, y2, color) {
var c_svgLine = document.createElementNS(NS, "line");
c_svgLine.setAttributeNS(null, "x1", x1);
c_svgLine.setAttributeNS(null, "y1", y1);
c_svgLine.setAttributeNS(null, "x2", x2);
c_svgLine.setAttributeNS(null, "y2", y2);
c_svgLine.setAttributeNS(null, "class", "line");
c_svgLine.style.stroke = color;
c_svgLine.style.width = 5;
return c_svgLine;
};
并线创建为这样:克,是SVG文件。
g.appendChild(c_line(50, 10, 100, 20,"red"));
在将颜色设置为红色的情况下,是否可以使用名称red而不是使用名称red而将原始值用作输入?所以沿着线的东西:
g.appendChild(c_line(50, 10, 100, 20,"255,60,245"));
我想设置颜色以这种方式,因为我不想拥有一个充满精致的颜色名称IE ["red","black","blue"....]
一个数组,但随机生成的颜色然而,许多行,我决定创建。
我现在已经做到了:)>但感谢您的回复和精彩的回答!我也会采纳你的建议! – 2015-03-31 18:19:37