【问题标题】:SVG animate has no methodSVG动画没有方法
【发布时间】:2013-01-04 05:42:28
【问题描述】:

我有一个 SVG (html):

    <div>
      <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
        <g id="radius-selector">
          <!-- Circle -->
          <circle id="radius-circle" cx="50%" cy="35%" r="25%" stroke="black" stroke-width="2" />
          <!-- Radius ring -->
          <circle id="radius-ring" cx="50%" cy="35%" r="12.5%" stroke="green" stroke-width="10" fill="none"/>
        </g>

      </svg>
    </div>

我正在尝试转换 SVG,使用 JQuery 来选择它:

$('#radius-ring')[0].animate({fill: "#223fa3", stroke: "#000", "stroke-width": 80, "stroke-opacity": 0.5}, 2000);

但我一直在控制台中收到错误:

TypeError: Object #<SVGCircleElement> has no method 'animate'
arguments: Array[2]
get message: function () { [native code] }
get stack: function () { [native code] }
set message: function () { [native code] }
set stack: function () { [native code] }
type: "undefined_method"
__proto__: Error

我是否需要实际安装插件或库来为 SVG 设置动画?我以为你能做到这一点?如果是这样,我将不胜感激在正确方向上的一点......

【问题讨论】:

    标签: jquery svg jquery-animate transform


    【解决方案1】:

    实际上您使用的是DOM 对象而不是jquery 对象。试试这个方法

     $('#radius-ring').animate({fill: "#223fa3", stroke: "#000", "stroke-width": 80, "stroke-opacity": 0.5}, 2000);
    

    而不是

     $('#radius-ring')[0].animate({fill: "#223fa3", stroke: "#000", "stroke-width": 80, "stroke-opacity": 0.5}, 2000);
    

    【讨论】:

    • 我需要为笔画宽度设置动画,首先我尝试不使用引号。多亏了你,我看到引号是必要的。
    猜你喜欢
    • 1970-01-01
    • 2021-12-15
    • 2013-08-19
    • 2021-10-16
    • 2015-09-02
    • 2020-07-20
    • 2017-03-08
    • 1970-01-01
    • 2019-04-13
    相关资源
    最近更新 更多