【发布时间】:2015-04-30 07:56:56
【问题描述】:
我有一个简单的 SVG,其中有一个元素围绕圆形路径旋转。当用户悬停时,通过更改 dur 属性可以加快旋转速度。问题是元素在发生时会跳转到不同的位置。怎么解决?
$('g').hover(
function() {
$(this).find('animateMotion').attr('dur', '3s');
},
function() {
$(this).find('animateMotion').attr('dur', '7s');
}
);
<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>
【问题讨论】: