![](/img/trans.png)
[英]Using Raphael JS, fill an SVG element with with a background-image with an offset
[英]Fill SVG element with with a background-image with an offset
我想做一些类似于这个Fill SVG path element with a background-image
但是,我想移动/偏移图像。 使用 CSS,可以通过设置background-image
和background-position
轻松完成。 我如何用 SVG 做到这一点?
您可以在模式元素上使用patternTransform
来转换模式; 它就像您可能已经熟悉的transform
属性一样工作。 有关详细信息,请参阅文档。
您可以使用带有fill
属性的pattern
和 SVG 元素。
这是一个示例:在位置 (10, 10) 处插入图像,偏移量为 (40, 550),大小为 (420, 340)。 请注意,您必须设置正确的x
/ y
和transform="translate(-x1 -y2)"
。
<p> <a href="https://i.imgur.com/MQHYB.jpg">Original image</a> </p> <svg version="1.1" width="500" height="400" style="background-color: #EEE;"> <defs> <pattern id="europe" patternUnits="userSpaceOnUse" width="1456px" height="1094px"> <image xlink:href="https://i.imgur.com/MQHYB.jpg"/> </pattern> </defs> <rect fill="url(#europe)" transform="translate(-30 -540)" x="40" y="550" width="420" height="340"/> </svg>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.