Animation SVG从中心点而不是左上角缩放动画
如何在SVG中使用Animation SVG从中心点而不是左上角缩放动画,animation,svg,svg-animate,Animation,Svg,Svg Animate,如何在SVG中使用animateTransform从中心点而不是左上角缩放对象 例如: <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100px" height="100px"> <circle style="fill:blue;" cx="50" cy="50" r="45"> <
animateTransform
从中心点而不是左上角缩放对象
例如:
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100px" height="100px">
<circle style="fill:blue;" cx="50" cy="50" r="45">
<animateTransform attributeName="transform"
type="scale"
from="0 0"
to="1 1"
begin="0s"
dur="1s"
repeatCount="indefinite"
/>
</circle>
</svg>
)
将缩放变换更改为使用additional=“sum”
并应用将圆转换为图像中心的附加变换。因此,与其在图像中心定义形状,不如将其中心定义为0
,然后使用transform
属性将其转换为50,50
(特定图像的确切中心)
非常感谢你!!这么简单。如果它不是一个圆,例如一条复杂的路径,你如何定义它在中心?只需计算准确的中心点,然后移动到那里,然后移动到真正的开始位置?
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100px" height="100px">
<circle style="fill:blue;" cx="0" cy="0" r="45" transform="translate(50 50)">
<animateTransform attributeName="transform"
type="scale"
additive="sum"
from="0 0"
to="1 1"
begin="0s"
dur="1s"
repeatCount="indefinite"
/>
</circle>
</svg>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100px" height="100px">
<defs>
<circle id="def-circle" style="fill:blue;" cx="0" cy="0" r="45" />
</defs>
<use xlink:href="#def-circle" transform="translate(50 50)">
<animateTransform attributeName="transform"
type="scale"
additive="sum"
from="0 0"
to="1 1"
beg="0s"
dur="1s"
repeatCount="indefinite" />
</use>
</svg>