0
这段Javascript代码创建了一个圆形对象,但不会为该圆圈设置动画。在Chrome中,我可以使用开发人员工具编辑HTML(添加一些空白;没有任何材料),这似乎说服Chrome进行动画制作。如何动画JS生成的SVG对象?
如何强制动画开始?
function f(x, y) {
var svg = document.getElementById('svg');
var circle = document.createElementNS(svg.namespaceURI, 'circle');
circle.setAttribute('cx', x);
circle.setAttribute('cy', y);
circle.setAttribute('r', '50');
var animation = document.createElementNS(svg.namespaceURI, 'animatemotion');
var path = 'm 0,0 l ' + (x + 500) + ',0'
animation.setAttribute('path', path);
animation.setAttribute('dur', '30s');
animation.setAttribute('fill', 'freeze');
circle.appendChild(animation);
svg.appendChild(circle);
}
f(50, 50);