我有一个简单的 SVG,其中有一个围绕圆形路径旋转的元素。当用户悬停时,通过更改dur属性使旋转速度加快。问题是元素在发生时会跳转到不同的位置。如何解决这个问题?
$('g').hover(
function() {
$(this).find('animateMotion').attr('dur', '3s');
},
function() {
$(this).find('animateMotion').attr('dur', '7s');
}
);Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<svg width='500' height='500'>
<g>
<path id='circle' d='M 250, 250 m -200, 0 a 200,200 0 1,0 400,0 a 200,200 0 1,0 -400,0' fill='none' stroke='red' stroke-width='10' />
<circle cx="50" cy="50" r="40" fill="red" transform='translate(-50, -50)'>
<animateMotion dur="7s" repeatCount="indefinite">
<mpath xlink:href="#circle" />
</animateMotion>
</circle>
</g>
</svg>Run Code Online (Sandbox Code Playgroud)