0

I have two SVG path animations that use <circle for the object to move along the path, how would it be possible to change their duration depending on each path separately, for instance, circle1 with a duration of 1s and circle2 with a duration of 2s? As it seems that changing the circle duration goes for all circles, not for their id-s

//Working
$('circle').find('animateMotion').attr('dur', '1s');

//Not working
$('circle1').find('animateMotion').attr('dur', '1s');
$('circle2').find('animateMotion').attr('dur', '2s');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<svg width="300" height="150">
					<path id="motionPath1"
					d="M 10 80 Q 52.5 10, 95 80 T 180 80"
					stroke="black" fill="transparent" />
				<circle class="circle" r=10 fill=red>
 				  <animateMotion dur="10s" repeatCount="indefinite">
 			      <mpath href="#motionPath1" />
 			  </animateMotion>
 			   </circle>
			</svg>
			<svg  width="300" height="150">
    <path id="motionpath2"
					d="M 10 80 Q 52.5 10, 95 80 T 180 80" stroke="black" fill="transparent"/>
  			         <circle class="circle2" r=10 fill=red>
  			         
             <animateMotion dur="20s" repeatCount="indefinite"
					rotate="auto">
                 <mpath href="#motionpath2" />
             </animateMotion>
         </circle>

4

1 回答 1

1

如果要引用 Jquery 中的任何圆圈,请使用$('circle'). 对于一个带有circle1id$('#circle1')的圆圈,您使用(注意哈希)。对于任何带有 class 的圆圈circle2,您可以使用$('.circle2')(注意点)。我在第一个圆圈中添加了一个 id 并用它引用它。在第二个圈子里,我继续circle2上课。第一个$('circle').find('animateMotion').attr('dur', '1s');作用于所有圈子,但之后会被覆盖。您可以将circle2类添加到其他元素,但不能将circle1id 添加到任何其他元素。

//Working
$('circle').find('animateMotion').attr('dur', '1s');

//Not working
$('#circle1').find('animateMotion').attr('dur', '1s');
$('.circle2').find('animateMotion').attr('dur', '2s');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<svg width="300" height="150">
					<path id="motionPath1"
					d="M 10 80 Q 52.5 10, 95 80 T 180 80"
					stroke="black" fill="transparent" />
				<circle id="circle1" class="circle" r=10 fill=red>
 				  <animateMotion dur="10s" repeatCount="indefinite">
 			      <mpath href="#motionPath1" />
 			  </animateMotion>
 			   </circle>
			</svg>
			<svg  width="300" height="150">
    <path id="motionpath2"
					d="M 10 80 Q 52.5 10, 95 80 T 180 80" stroke="black" fill="transparent"/>
  			         <circle class="circle2" r=10 fill=red>
  			         
             <animateMotion dur="20s" repeatCount="indefinite"
					rotate="auto">
                 <mpath href="#motionpath2" />
             </animateMotion>
         </circle>

于 2019-12-13T15:53:07.580 回答