问题描述
我在玩 Firefox 3.6 并希望在单击时向 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);
但是另一种执行 setAttribute
行的方法是:
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);
但结果对象没有我期望的 setTranslate(x,y)
方法;也没有任何二传手.奇怪的是 group2.translate.baseVal.getItem(0)
确实有它,但没有可用的克隆或复制方法.
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?
推荐答案
参见 SVGSVGElement.createSVGTransform.
示例:
var tfm = svgroot.createSVGTransform();
tfm.setTranslate(x,y);
这篇关于创建一个新的 SVGTransform 对象以附加到 SVGTransformList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!