Ich habe diesen SVG-Kreis mit einer Animation.So erstellen SVG-Animations-Tag mit Javascript
<circle cx="30" cy="50" r="15" fill="blue" stroke="black" stroke-width="1">
<animateMotion path="M 0 0 H 300 Z" dur="8s" repeatCount="indefinite" />
</circle>
Es funktioniert gut. Ich möchte die gleiche Sache mit Javascript machen, also wenn ich einen Knopf anklicke, würde es den gleichen Kreis mit der gleichen Animation verursachen.
hier ist mein Versuch:
var animateMotion = document.createElementNS("http://www.w3.org/2000/svg", "animateMotion");
animateMotion.setAttribute("dur","8s");
animateMotion.setAttribute("d", "M 0 0 H 300 Z");
animateMotion.setAttribute("repeatCount","indefinite");
//assuming that I already created my circle
myCircle.appendChild(animateMotion);
Sieht aus, als ob Sie bereits die richtige Antwort haben. Ich denke nicht, dass dies momentan in Webkit funktioniert, aber es sollte anderswo funktionieren. –
Ich habe ein ähnliches Problem mit Firefox. – m93a
Dokumentation: [W3C Empfehlung SVG 1.1. 2011, Sekte. "Animation"] (http://www.w3.org/TR/SVG11/animate.html) – handle