javascript - 如何设置 SVG 内圆圈中的参数之一的样式?

标签 javascript css svg

我有一个 SVG,里面有圆圈。我希望它们的半径永远增加和减少(就像一个脉动的圆圈)。

我的问题是,我可以使用@keyframes 来完成吗?或者我需要jquery吗?如果是这样,怎么做到的?

这是我的代码:

<div class="mapa">
    <svg (svg code here......)
        <circle opacity="0.3" cx="842" cy="451.814" r="25.582" id="1"/>
        <circle opacity="0.3" cx="542" cy="405.814" r="25.582" id="1"/>
    </svg>
</div>

如何设置“r”参数的样式?

我读到我无法设置“r”参数的样式,但这行得通:

<circle cx="168" cy="179" r="59"
        fill="white" stroke="black"
        onmouseover="evt.target.setAttribute('r', '72');"
        onmouseout="evt.target.setAttribute('r', '59');"
/>

但是,我想做半径不断增减?而不是 mouseover/mouseleave。类似于(r=25,然后 r=30,然后回到 25,一直持续下去)。我该怎么做?

感谢您的宝贵时间,如果您能给我任何提示,我将不胜感激!

最佳答案

尝试使用svg smil animate

<svg width="150" height="150">

  <circle opacity="0.3" cx="84%" cy="45%" r="3" id="1">
    <animate attributeName="r" values="3; 10; 3" keyTimes="0; 0.5; 1" dur="1s" repeatCount="indefinite" />
  </circle>
  
  <circle opacity="0.3" cx="50%" cy="50%" r="10" id="2">
    <animate attributeName="r" values="10; 3; 10" keyTimes="0; 0.5; 1" dur="1s" repeatCount="indefinite"/>
  </circle>

</svg>

关于javascript - 如何设置 SVG 内圆圈中的参数之一的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55927040/

相关文章:

javascript - 文本扩展和背景颜色的动画

css - Angular NgStyle : list image style

javascript - 白天时间热图 - 颜色未显示

javascript - 不能将原型(prototype)函数放入promise解析中吗?

c# - 打开/关闭 'popped-up' 窗口时出现问题

javascript - Jquery 数据表在表单发布后填充

css - 如何让 Elm 动画师使用 CSS 动画为 SVG 元素制作动画?

html - 强制包含图像 DIV 的主 DIV float 中心

css - 使此布局正常工作的正确方法是什么?

javascript - phantomjs - 文本变换旋转扭曲文本旋转