How to append an element inside another on snapsvg?

。_饼干妹妹 提交于 2019-12-25 06:23:38

问题


I'm building a domino piece using Snapsvg http://snapsvg.io/

Here is the code so far.

var s = Snap(800,600);

// elem structure
var elem = s.rect(10,10,100,200);
var s1  = s.rect(0,0,90,90);

elem.attr({
    fill: '#fff',
    stroke: '#000',
    strokeWidth: 2
});

s1.attr({
    fill: '#bada55'
});

s1.append(elem)

I built the piece structure var elem that is width:100 and height:200 and I built an square var s1 width:90 height:90. I'm trying to append s1 inside elem. When i use s1.append(elem), the elem disappears, what am I doing wrong?


回答1:


In SVG graphical elements i.e. rect, polygon etc are not nestable.

There are containers (Paper.group) which can contain graphical elements which you can add transforms to to move multiple elements at once if you want. You could create one of those and put both your rect elements within it as siblings.



来源:https://stackoverflow.com/questions/23935631/how-to-append-an-element-inside-another-on-snapsvg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!