【问题标题】:SVG createElementNS 'use' is it possible?SVG createElementNS“使用”有可能吗?
【发布时间】:2015-06-18 05:24:14
【问题描述】:

缩短,我正在使用(使用)复制将代码添加到 DOM 的正方形(路径),但是只有 1px(调试镶边)。对第六块用户是不可见的! 谢谢你! code in: codepen

$(function() {
  $('#svg').css('visibility', 'visible');   
  $('#svg use').css('fill', '#fff');

  function addAnim() {
    var $first = $('#svg use:not(.anim):first');
    $first.attr('class', 'anim').css('fill', '#F15A29');    
    $first.animate({fill : '#F15A29'}, 500);
    setTimeout(function() {
      addAnim();
    }, 100);
  }

  function replicar(){
      var svg = document.getElementById('svg'); 
      var elemento= document.createElementNS('ttp://www.w3.org/2000/svg', 'use');
      elemento.setAttribute('xlink:href', '#shape');
      elemento.setAttribute('y', '62');
      elemento.setAttribute('x', '124');
      elemento.setAttribute('fill', '#3D6EB5');
      svg.appendChild(elemento);   


  addAnim();
  replicar(); 
});

【问题讨论】:

    标签: javascript animation svg


    【解决方案1】:

    您在这一行中缺少一个“h”:

    var elemento= document.createElementNS('http://www.w3.org/2000/svg', 'use');
    

    另外,xlink 属性需要加上setAttributeNS

    elemento.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', '#shape');
    

    【讨论】:

    • 你帮了我很多!我现在很高兴。非常感谢。
    猜你喜欢
    • 2011-03-30
    • 2011-04-07
    • 2016-09-09
    • 2011-03-25
    • 2011-09-13
    • 2011-12-31
    • 2019-06-24
    • 2018-04-18
    • 2012-04-08
    相关资源
    最近更新 更多