Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a new SVGTransform object to append to SVGTransformList

Tags:

javascript

svg

I was playing with firefox 3.6 and wanted to add a translation to an svg element when clicked; this element already had other translations on it.

var svgs = document.getElementsByTagName("svg:svg");
var group = svgs[0].childNodes[1];
group.addEventListener("click",function(e){
    var group2 = group.cloneNode(true);
    group2.setAttribute("transform", group2.getAttribute("transform")+" translate(10,10)");
    svg2.insertBefore(whole2, whole);
},false);

But another way to do the setAttribute line would be:

group2.translate.baseVal.appendItem(newSVGTransformTranslation);

Where I'm getting stuck is I can call

newSVGTransformTranslation =
  new SVGTransform(SVGTransform.SVG_TRANSFORM_TRANSLATE);

but the resulting object does not have the setTranslate(x,y) method that I expect; nor any setters. Oddly group2.translate.baseVal.getItem(0) does have it, but no clone or copy methods are available.

I must be using the constructor incorrectly. Does anyone have an example of the correct form?

like image 917
dlamblin Avatar asked Nov 17 '10 07:11

dlamblin


1 Answers

See SVGSVGElement.createSVGTransform.

An example:

var tfm = svgroot.createSVGTransform();
tfm.setTranslate(x,y);
like image 78
Erik Dahlström Avatar answered Nov 14 '22 21:11

Erik Dahlström