【问题标题】:Trying to pass string as function argument to SVG试图将字符串作为函数参数传递给 SVG
【发布时间】:2012-01-18 02:26:27
【问题描述】:

我正在尝试动态创建这个函数:

svg.path($('#shape23'), 
path.move(333,410)
.smoothC(333,410,333,410)
.smoothC(217.5,415.75,217.5,415.75)
.smoothC(333,500,333,500)
.close(),  {fill: '#CCCCCC'});

...第二个参数的变量值(从 path.move 到 close()):

var myPath = 'path.move(333,410)';
myPath += '.smoothC(333,410,333,410)';
myPath += '.smoothC(217.5,415.75,217.5,415.75)';
myPath += '.smoothC(333,500,333,500)';
myPath += '.close()';

 svg.path($('#shape23'), myPath,  {fill: '#CCCCCC'});

...但是我遇到了解析错误。

在我拔掉剩下的头发之前,谁能帮忙?

【问题讨论】:

    标签: javascript jquery jquery-svg


    【解决方案1】:

    试试这个

    svg.path($('#shape23'), eval(myPath),  {fill: '#CCCCCC'});
    

    【讨论】:

      【解决方案2】:

      我应该使用那些 svg 构造函数,我使用 XML...

      path = Document.createElementNS( 'http://www.w3.org/2000/svg', 'path' );
      path.setAttribute( 'id', '#shape23' );
      path.setAttribute( 'd', 'm33,410 c333,410 217.5,415.75 333,500z' );
      path.setAttribute( 'fill', '#CCCCCC' );
      

      不确定路径指标,但您可以修复它们。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-19
        • 2017-04-25
        • 2012-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-12
        相关资源
        最近更新 更多