How to translate an SVG group by a percentage of the viewport

前端 未结 1 930
眼角桃花
眼角桃花 2020-12-09 14:54

I have an svg that is in a (group) and I would like to scale it and then translate it by a percentage of the viewport. Most

相关标签:
1条回答
  • 2020-12-09 15:25

    Stick the <g> element in an inner <svg> element and add x and y attributes with percentage values to the inner <svg> element to translate it.

    <svg>
      <svg x="10%" y="20%">
        <g transform="scale(1, 1)">
          <rect x="45%" y="25%" height="50%" width="10%"/>
        </g>
      </svg>
    </svg>
    

    If you want the scale to apply first you would put the <svg> element inside the <g> instead.

    0 讨论(0)
提交回复
热议问题