【发布时间】:2015-04-13 05:30:55
【问题描述】:
第一次学习SVG,遇到<defs>、<g>和<use>。我注意到,每当使用<g> 对元素进行分组,然后使用<use> 使用时,如果执行旋转,它将应用于整个坐标系。例如,如果在<use xlink:href="#point" x="105" y="-105" transform="rotate(90 50,50)"/> 上旋转90 度,然后在x="100" 上旋转,svg 图像沿 Y 轴移动。这会造成处理许多图像的混乱。有什么技术可以避免或即兴发挥吗?
<svg width="500" height="400">
<defs>
<g id="point">
<rect rx="4" ry="4" y="50" width="50" height="50" fill="black"></rect>
<circle cx="50" cy="50" r="50" fill="black"/>
<circle cx="50" cy="50" r="5" fill="white"/>
</g>
</defs>
<use xlink:href="#point" x="0" y="0" transform="rotate(270 50,50)"/>
<use xlink:href="#point" x="0" y="-105" transform="rotate(180 50,50)"/>
<use xlink:href="#point" x="105" y="0" transform="rotate(0 50,50)"/>
<use xlink:href="#point" x="105" y="-105" transform="rotate(90 50,50)"/>
</svg>
【问题讨论】: