Why nest an <svg> element inside another <svg> element?

前端 未结 4 389
感情败类
感情败类 2020-12-28 13:25

Why would a demo such as this: http://jsbin.com/ejorus/2/edit, have an element nested inside another element?



        
4条回答
  •  被撕碎了的回忆
    2020-12-28 14:22

    You're right (as you say in Mr. Alien's answer) that both SVG elements have the same relative positions, and indeed the graph displays fine without the outer SVG.

    The reason I added it is because the JavaScript (which I needed to stop the labels getting squished) uses the SVG element's transform matrix (caused by the applied viewBox attribute) to unscale the text.

    Unfortunately the returned matrix doesn't take account of transformations applied to the SVG element itself, so I needed to get the transform matrix relative to an outer element that used the initial coordinate system instead. Hope that helps.

提交回复
热议问题