我正在使用GWT和GWTGraphics库来为svg Path元素创建动画。 我使用GWTGraphics库创建路径元素和animateTransform元素(女巫被追加到路径元素)来创建旋转动画。SVG动画无法在Chrome中使用(在GWT中使用animateTransform)
我在Firefox 4.0中测试过,它工作正常。然后我在Chrome(版本17)和Opera(11.61)中测试,但没有任何反应。所以我尝试复制html,因为它是使用Chrome开发工具由gwt代码生成的,并使用复制的代码创建了一个简单的html文件。令我惊讶的是,这个新的html文件就像在Chrome中一样工作(并且也在Firefox和Opera中工作)。 我的问题是:为什么在GWT代码中生成的元素的动画不起作用?而通过复制代码创建的HTML文件中的元素动画正在运行?
GWT代码:
private void animateTest(Shape shape){
Element anim = SVGUtil.createSVGElementNS("animateTransform");
SVGUtil.setAttributeNS(anim, "attributeType", "xml");
SVGUtil.setAttributeNS(anim, "attributeName", "transform");
SVGUtil.setAttributeNS(anim, "type", "rotate");
SVGUtil.setAttributeNS(anim, "from", "360" + " " + CENTER_X + " " + CENTER_Y);
SVGUtil.setAttributeNS(anim, "to", "0" + " " + CENTER_X + " " + CENTER_Y);
SVGUtil.setAttributeNS(anim, "dur", "2" + "s");
SVGUtil.setAttributeNS(anim, "repeatCount", "indefinite");
shape.getElement().appendChild(anim);
}
生成的HTML代码:
<svg overflow="hidden" width="300" height="300"><defs></defs>
<path fill="#cfe2f3" fill-opacity="1.0" stroke="#a4c2f4" stroke-opacity="1.0" stroke-width="1" d=" M150 70 A80,80 0 0,0 70,150 L62 150 A88,88 0 0,1 150,62 L150 70 z">
<animateTransform attributeType="xml" attributeName="transform" type="rotate" from="360 150 150" to="0 150 150" dur="2s" repeatCount="indefinite"></animateTransform>
</path>
</svg>
显示一些代码! – Sirko 2012-03-19 13:46:54
我发现了一些关于使用javascript进行SVG转换的问题。我可以尝试另一个库(如lib-gwt-svg)或创建本机方法,但如果问题更复杂,我可能找不到解决方法。 – 2012-03-19 14:54:07