2013-12-16 53 views
3

我嘗試將ImageElement添加到GElement。雖然<image>元素正確創建在<g>下,但它沒有顯示出來。如果我複製由Dart創建的<image>元素,並將其添加到html文件中,則會顯示。我使用下面的代碼片段:Dart svg ImageElement沒有顯示

ImageElement aImage = new ImageElement(); 
aImage.setAttribute('x', '$x'); 
aImage.setAttribute('y', '$y'); 
aImage.setAttribute('width', '30'); 
aImage.setAttribute('height', '30'); 
aImage.setAttribute('xlink:href', 'http://icons.iconarchive.com/icons/deleket/sleek-xp-software/256/Yahoo-Messenger-icon.png'); 
group.append(a); 
+0

什麼是「GroupElement」?在html5中我沒有看到任何''標籤。 –

+0

[GElement](https://api.dartlang.org/docs/channels/stable/latest/dart_svg/GElement.html) – ringstaff

回答

4

您必須設置使用getNamespacedAttributes將href(見this)。另外,確保組元素位於SvgSvgElement上。這對我有效:

svg.SvgSvgElement svgBase = new svg.SvgSvgElement(); 
svg.ImageElement aImage = new svg.ImageElement(); 
svg.GElement group = new svg.GElement(); 


aImage.setAttribute('x', '50'); 
aImage.setAttribute('y', '50'); 
aImage.setAttribute('width', '30'); 
aImage.setAttribute('height', '30'); 
aImage.getNamespacedAttributes('http://www.w3.org/1999/xlink')['href'] = 'http://icons.iconarchive.com/icons/deleket/sleek-xp-software/256/Yahoo-Messenger-icon.png'; 

group.append(aImage); 
svgBase.append(group); 
querySelector('#container').append(svgBase); 
+0

你是英雄!經過兩天的嘗試,我用getNamespacedAttributes('http://www.w3.org/1999/xlink')['href'] ...但是.setAttribute(「href」,link)有什麼區別? – Dafen