0

我想替换这一行:

 polygon.setAttribute("points", "50,0 200,0 125,150");

它适用于永久号码:

演示 jsFiddle

用这条线:

polygon.setAttributeNS (null, "points", ("LeftWidth,0 RightWidth,0 RopTringleX,RopTringleY"));

jsfiddle 演示

我怎样才能做到这一点?很多谢谢。

编码:

function CreateSVG () {
            var xmlns = "http://www.w3.org/2000/svg";
            var boxWidth = 250;
            var boxHeight = 250;
            var LeftWidth=(250-boxHeight)/2;
            var RightWidth=250-LeftWidth;
            var RopTringleX=(RightWidth-(boxWidth/2));
            var RopTringleY=(boxHeight);


            var svgElem = document.createElementNS (xmlns, "svg");
            svgElem.setAttributeNS (null, "viewBox", "0 0 " + boxWidth + " " + boxHeight);
            svgElem.setAttributeNS (null, "width", 250);
            svgElem.setAttributeNS (null, "height", 250);
            svgElem.style.display = "block";

            var polygon = document.createElementNS (xmlns, "polygon");
            svgElem.appendChild (polygon);
alert(RopTringleY);        

            polygon.setAttributeNS (null, "points", ("LeftWidth,0 RightWidth,0 RopTringleX,RopTringleY"));

            var path = document.createElementNS (xmlns, "path");
            path.setAttributeNS (null, 'stroke', "white");
            path.setAttributeNS (null, 'stroke-width', 4);
            path.setAttributeNS (null, 'fill', "yellow");
            polygon.appendChild (path);

            var svgContainer = document.getElementById ("svgTriangle");

            svgContainer.appendChild (svgElem); 
            alert(boxWidth + ' ' + boxHeight);     
        }
CreateSVG ();
​
4

1 回答 1

2
polygon.setAttribute("points", LeftWidth + ",0 " + RightWidth + ",0 " + RopTringleX + "," + RopTringleY);
于 2012-08-30T14:23:13.060 回答