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
.
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.
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).
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
:
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).
Thanks in advance for any help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…