围绕另一个旋转圆旋转圆圈

苏哈斯·巴图

我在 svg 中有一个围绕给定点旋转的圆圈。我又加了一个圈。我想围绕第一个旋转圆旋转第二个圆。我怎样才能做到这一点?到目前为止,我能够围绕一个点旋转第一个圆。第二个圆圈正在旋转,但不围绕第一个旋转。我正在分享我的代码:

firstCircle= document.createElementNS(namespace, "circle");
firstCircle.setAttributeNS(null, "id", "firstCircle");
firstCircle.setAttributeNS(null, "cx", 700);
firstCircle.setAttributeNS(null, "cy", 400);
firstCircle.setAttributeNS(null, "r", 30);
firstCircle.setAttributeNS(null, "fill", "#0077BE");
svg.appendChild(firstCircle);

firstCircleAnimate = document.createElementNS(namespace, "animateTransform");
firstCircleAnimate.setAttributeNS(null, "attributeName", "transform");
firstCircleAnimate.setAttributeNS(null, "type", "rotate");
firstCircleAnimate.setAttributeNS(null, "from", "0 400 400");
firstCircleAnimate.setAttributeNS(null, "to", "360 400 400");
firstCircleAnimate.setAttributeNS(null, "begin", "0s");
firstCircleAnimate.setAttributeNS(null, "dur", "5s");
firstCircleAnimate.setAttributeNS(null, "repeatCount", "indefinite");
firstCircle.appendChild(firstCircleAnimate);

secondCircle= document.createElementNS(namespace, "circle");
secondCircle.setAttributeNS(null, "id", "secondCircle");
secondCircle.setAttributeNS(null, "cx", 760);
secondCircle.setAttributeNS(null, "cy", 400);
secondCircle.setAttributeNS(null, "r", 10);
secondCircle.setAttributeNS(null, "fill", "#D0D5D2");
svg.appendChild(secondCircle);

secondCircleAnimate =  document.createElementNS(namespace, "animateTransform");
secondCircleAnimate.setAttributeNS(null, "attributeName", "transform");
secondCircleAnimate.setAttributeNS(null, "type", "rotate");
secondCircleAnimate.setAttributeNS(null, "from", "0 " + firstCircle.getAttributeNS(null, "cx") + " " + firstCircle.getAttributeNS(null, "cy"));
secondCircleAnimate.setAttributeNS(null, "to", "360 " + firstCircle.getAttributeNS(null, "cx") + " " + firstCircle.getAttributeNS(null, "cy"));
secondCircleAnimate.setAttributeNS(null, "begin", "0s");
secondCircleAnimate.setAttributeNS(null, "dur", "2s");
secondCircleAnimate.setAttributeNS(null, "repeatCount", "indefinite");
secondCircle.appendChild(secondCircleAnimate );

在这里,我将secondCircleAnimatefrom 和 to 属性设置为firstCircle的中心坐标,但第一个圆本身是旋转的,在 DOM 中,第一个圆的中心似乎在整个旋转过程中都没有改变。那么如何围绕旋转的第一个圆圈旋转第二个圆圈?

提前致谢。

苏哈斯·巴图

终于找到了解决办法。<g>在第二个圆圈周围添加了一个标签。我添加了相同animateTransform<g>并使其围绕中心点和内部旋转<g>,对于第二个圆,我使第二个圆围绕第一个圆旋转。

重要的是第一圈的持续时间和第二圈的持续时间应该相等(只是为了使它们的旋转同步)。

添加的代码是:

group= document.createElementNS(namespace, "g");
group.setAttributeNS(null, "id", "group");
svg.appendChild(group);

groupAnimate=  document.createElementNS(namespace, "animateTransform");
groupAnimate.setAttributeNS(null, "attributeName", "transform");
groupAnimate.setAttributeNS(null, "type", "rotate");
groupAnimate.setAttributeNS(null, "from", "0 400 400");
groupAnimate.setAttributeNS(null, "to", "360 400 400");
groupAnimate.setAttributeNS(null, "begin", "0s");
groupAnimate.setAttributeNS(null, "dur", "5s");
groupAnimate.setAttributeNS(null, "repeatCount", "indefinite");
group.appendChild(groupAnimate);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

围绕另一个任意点旋转点

来自分类Dev

围绕另一个CGPoint旋转CGPoint

来自分类Dev

围绕另一个元素旋转元素-CSS

来自分类Dev

围绕另一个旋转对象

来自分类Dev

围绕另一个任意点旋转点

来自分类Dev

围绕另一个gameObject旋转gameObjects

来自分类Dev

围绕另一个圆圈制作圆圈动画

来自分类Dev

在Java中将一个对象围绕另一个对象旋转

来自分类Dev

在Java中将一个对象围绕另一个对象旋转

来自分类Dev

围绕另一个点旋转一个点-错误的方向

来自分类Dev

围绕另一个点旋转一个点

来自分类Dev

Mathematica:围绕另一个点旋转一个点

来自分类Dev

如何使一个GameObject在旋转平面中围绕Unity中的另一个gameObject旋转

来自分类Dev

javafx 如何围绕另一个节点旋转一组节点

来自分类Dev

在fabric.js 中围绕另一个对象旋转另一个独立对象

来自分类Dev

围绕另一个点和X轴旋转点

来自分类Dev

(Java-LibGDX)如何将向量旋转到围绕另一个向量的特定旋转

来自分类Dev

Threejs在3d矩阵轴上围绕另一个对象旋转一个对象

来自分类Dev

UIBezierPath围绕圆自身,swift和SpriteKit内的一个点旋转

来自分类Dev

Kineticjs旋转一个圆圈

来自分类Dev

旋转一个重复的屏幕而不旋转另一个Windows 8

来自分类Dev

将旋转的div与另一个div对齐

来自分类Dev

旋转节点以查看另一个节点

来自分类Dev

另一个轴上的旋转动画

来自分类Dev

在另一个图像上旋转图像

来自分类Dev

将旋转的div与另一个div对齐

来自分类Dev

跟随另一个正在旋转的物体

来自分类Dev

3D旋转矩阵(旋转到另一个参考系统)

来自分类Dev

如何从SpriteKit中已经旋转的另一个创建旋转的纹理

Related 相关文章

热门标签

归档