在fiddle中查看解决方案(点击蓝色按钮):
将按钮放入"g"中,并使用转换使其旋转:
const button = d3.select("#button");
let angle = 60;
button.on("click", () => {
angle = -angle;
button.transition().duration(1000).attr("transform", `translate(${cX}, ${cY}) rotate(${angle})`);
});
另一种选择是沿着路径使用 animateMotion:
<svg width="300" height="200">
<path fill="none" stroke="blue" stroke-width="3"
d="M 20,20 A 100,100 0 0 0 220,20" />
<circle r="10" fill="white" stroke="blue" stroke-width="3">
<animateMotion dur="3s" repeatCount="indefinite"
path="M 20,20 A 100,100 0 0 0 220,20 A 100,100 1 1 1 20,20" />
</circle>
</svg>