最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - SVG createElementNS 'use' is it possible? - Stack Overflow

programmeradmin2浏览0评论

shortening, I'm using (use) to replicate the square (path) the code is added to the DOM however, only 1px (debug chrome). Is not visible to the sixth block the User! thank you! 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/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(); 
});

shortening, I'm using (use) to replicate the square (path) the code is added to the DOM however, only 1px (debug chrome). Is not visible to the sixth block the User! thank you! 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/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(); 
});
Share Improve this question edited Jan 16, 2015 at 2:04 Jorg 7,2504 gold badges47 silver badges66 bronze badges asked Jan 16, 2015 at 1:57 alexsouzadobrasilalexsouzadobrasil 234 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

You are missing an 'h' in this line:

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

Also, xlink attributes need to be added with setAttributeNS.

elemento.setAttributeNS('http://www.w3/1999/xlink', 'xlink:href', '#shape');
发布评论

评论列表(0)

  1. 暂无评论