gpt4 book ai didi

javascript - 如何将图像添加到 svg 圆的中心?

转载 作者:数据小太阳 更新时间:2023-10-29 04:37:05 24 4
gpt4 key购买 nike

我正在尝试将图像添加到 SVG 圆的中心。我尝试了模式

<pattern id="image_birds" x="0" y="0" patternUnits="userSpaceOnUse" height="100" width="100">
<image x="0" y="0" xlink:href="birds.png" height="50" width="50"></image>
</pattern>

但它不会使图像居中。我正在使用 Javascript。

最佳答案

剪辑应该可以满足您的需求:https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Clipping_and_masking

类似于:

<clipPath id="cut-off-bottom">
<circle cx="100" cy="100" r="50" />
</clipPath>

<image x="25" y="25" xlink:href="http://placehold.it/150.png" height="150" width="150" clip-path="url(#cut-off-bottom)" ></image>

您可以在此处查看此示例的结果:http://jsbin.com/EKUTUco/1/edit?html,output

由您根据图像的大小通过 xy 属性在 javascript 中将图像居中。

关于javascript - 如何将图像添加到 svg 圆的中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18587107/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com