SVG createElementNS'使用'有可能吗?

ale*_*sil 1 javascript animation svg

缩短,我正在使用(使用)复制广场(路径),但代码被添加到DOM,但只有1px(调试chrome).第六块用户看不到!谢谢! 代码: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(); 
});
Run Code Online (Sandbox Code Playgroud)

Pau*_*eau 6

你在这一行中缺少'h':

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

此外,还需要添加xlink属性setAttributeNS.

elemento.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', '#shape');
Run Code Online (Sandbox Code Playgroud)