HTML5中 svg的animateTransform中rotate类型中围绕点设定

之前在做SVG动画中遇到的问题:在SVG动画效果中,怎么让一个圆围绕另一个动态圆转动,即比如太阳系转动,地球围着太阳转,月球围着地球转,卫星围着地球转。

之后发现可以通过嵌套的方式来达到目的:

先看代码

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<svg xmlns="http://www.w3.org/2000/svg" width="800" height="600">
			<circle cx="300" cy="300" r="50" fill="red"></circle>
			<g>
				<circle cx="100" cy="300" r="20" fill="blue"></circle>
				<g>
					<circle cx="50" cy="300" r="10" fill="yellow"></circle>
				<animateTransform attributeName="transform" from ="0 100 300 " 
					to="360 100 300 " type="rotate" begin="0s" dur="10s" repeatCount="indefinite">
				</animateTransform>
			
				</g> 
				<g>
					<circle cx="130" cy="300" r="5" fill="green"></circle>
				<animateTransform attributeName="transform" from ="0 100 300 " 
					to="360 100 300 " type="rotate" begin="0s" dur="3s" repeatCount="indefinite">
				</animateTransform>
			
				</g>
				<animateTransform attributeName="transform" from ="0 300 300 " 
					to="360 300 300 " type="rotate" begin="0s" dur="20s" repeatCount="indefinite">
				</animateTransform>
			
			</g>
			
			
		</svg>
	</body>
</html>

即可完成所要效果

那么如果是没有嵌套的话,那么效果使会围绕着固定点转动,即地球围绕着太阳转。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值