How can I give a Raphael element a fill that moves as the element moves, like how the CSS background-image
of a position: absolute;
HTML element would keep the same position relative to its location as it moved?
Here's an example demo: how can I make the background image pattern of the Raphael element (the triangular path) behave the same while dragged as the HTML element (the square div)?
http://jsbin.com/oxuyeq/8/edit
This question is essentially the opposite of How to make a pattern “fixed” in Raphael.js / IE? with the polarised glasses simulator - I want to make the IE-specific behaviour they were trying to avoid happen consistently, in all browsers (including IE8).
As detailed in that other question, in IE8 (VML) only, the Raphael element behaves how I want; but even this is erratic: various things like calling setSize
on the paper
element or re-defining the fill (essentially, anything forcing a redraw) cause it to switch to the other behaviour.
There's a question similar to this for pure SVG, but without any good answers at time of writing, and certainly none that work for Raphael.
Edit 2: Watching what happens in SVG mode, it seems that every Raphael transform also automatically does the same matrix transform to the svg <pattern>
element. I think this is what causing the behaviour I'm trying to avoid - I think patternContentUnits
and patternUnits
are unrelated. There's an unresolved issue that seems related here (highlighting the same problem with clip-rect, next to the line this.pattern && updatePosition(this);
) - https://github.com/DmitryBaranovskiy/raphael/issues/638
So one possibility might be to define a custom attribute that applies a transform to the element without also applying it to the pattern. Sounds difficult - might require hacking Raphael or duplicating lots of Raphael transform code. Hopefully there's some other way. And god help us making this work in VML...
Edit 3: Some potentially relevant information, it's not just path fills that have this problem. Raphael image
elements created with paper.image()
don't have this problem in SVG mode but have a very similar problem that is really bad in IE8 VML mode. Here's a demo of several ways to make image elements move, and here's a side-by-side comparison showing how they all work flawlessly in non-IE and all fail in IE: