Dokümanıma bir SVG var ve bunun gibi javascript ile buna bir sembol ekleyin: Oluşan kodunu tam olarak HTML wich yazılmış başka bir düğüm ile aynı iseNeden SVG javascript ile oluşturulan öğeyi gösterilmiyor?
var myScene =document.getElementById('myScene');
var useSVG = document.createElement('use');
useSVG.setAttribute('xlink:href','spriteSheet.svg#mySymbol');
useSVG.setAttribute('x','10');
useSVG.setAttribute('y','30');
useSVG.setAttribute('width','10');
useSVG.setAttribute('height','10');
myScene.appendChild(useSVG);
sembolü görünmüyor olduğu doğru şekilde görüntülendi. ayıklayıcısında gösterilen
Kodu:
<svg id="myScene" width="200px" height="200px">
<use xlink:href="spriteSheet.svg#mySymbol" x="5" y="50" width="10" height="10"></use>
<!-- this one was in html, it is visible -->
<use xlink:href="spriteSheet.svg#mySymbol" x="10" y="30" width="10" height="10"></use>
<!-- this one is added with javascript. it is not displayed -->
</svg>
aşağıda cevap yeterli değildir ama noktaları doğru yöne:
Burada fazla bilgi ve olası bir geçici çözüm bulundu. Burada 'use' öğesini oluşturmak için' document.createElement' yerine 'document.createElementNS' kullanmak zorundasınız. Bu [cevap] (http://stackoverflow.com/questions/16488884/add-svg-element-to-existing-svg-using-dom) benzer sorunu çözdü. –
Her şeyi denedim, işe yaramayacağım. Bir çalışma örneği de bulamıyor. Çözümüm, kodlanmış USE etiketine bir kimlik vermek ve node.cloneNode() ile kopyalamaktır. Hala çalışan bir örnek arıyoruz. – bokan