I have some SVG objects with a tiled image background using fill="url(#background)
, where I'm defining #background
as a pattern
containing just an image
.
(我有一些SVG对象,使用fill="url(#background)
来平铺图像背景,其中我将#background
定义为仅包含image
的pattern
。)
However, when the object is relocated by settings its x
/ y
attributes (or cx
/ cy
, or whatever else defines the offset), the background does not move with it.
(但是,当通过设置对象的x
/ y
属性(或cx
/ cy
或其他定义偏移量)来重定位对象时,背景不会随之移动。)
How do I make the background move as well?
(如何使背景也移动?)
From How would I move an SVG pattern with an element I tried to set the patternContentUnits='objectBoundingBox'
but that just turns the image into a solid color blob (oddly, though, colored according to the image, as if it were just the first pixel or some such).(从如何移动带有元素的SVG模式开始,我尝试设置patternContentUnits='objectBoundingBox'
但这只是将图像变成纯色斑点(不过,奇怪的是,根据图像进行了着色,就好像它只是第一个像素等)。)
Here is a jsfiddle illustrating all of this - the top rect
has been turned into a solid color, and then bottom rect
has the background image but it doesn't move with the rect
:
(这是一个说明所有这些的jsfiddle-顶部rect
已变成纯色,然后底部rect
具有背景图像,但不会随rect
移动:)
http://jsfiddle.net/x8nkz/17/
(http://jsfiddle.net/x8nkz/17/)
I know that if you were using transform="translate(...)"
instead of setting the x
/ y
attributes, the background does get translated as well, but the existing codebase I'm working within doesn't use translate for positioning (and it would have other unintended consequences on the rest of the application).
(我知道,如果您使用的是transform="translate(...)"
而不是设置x
/ y
属性,那么背景的确也会得到翻译,但是我正在使用的现有代码库不会将translate用于定位(这会对应用程序的其余部分产生其他意想不到的后果)。)
Thanks in advance for any help.
(在此先感谢您的帮助。)
ask by Yang translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…