Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a pattern with Raphaeljs?
    text
    copied!<p>I'm trying to add a grid pattern to my shapes, is there something I'm missing? This is the way I added it:</p> <p><a href="http://jsfiddle.net/qQDt9/" rel="nofollow">** <strong>Fiddle</strong> **</a></p> <pre><code>var paper = new Raphael(document.getElementById('canvas_container'), '100%', '100%'); $('&lt;pattern id="mygrid" width="10" height="10" patternUnits="userSpaceOnUse"&gt;\ &lt;polygon points="5,0 10,10 0,10" stroke="black" /&gt;\ &lt;/pattern&gt;').appendTo('svg defs'); var circle = paper.circle(60, 60, 50); circle.attr("fill","url(#mygrid)"); </code></pre> <p>I think it's probably because the document is loaded before I add the pattern<br/> This is the html after the pattern is added (the circle is not being fill):</p> <pre><code>&lt;div id=canvas_container&gt; &lt;svg height="100%" version="1.1" width="100%" xmlns="http://www.w3.org/2000/svg" style="overflow: hidden; position: relative;"&gt; &lt;desc style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"&gt;Created with Raphaël 2.1.2&lt;/desc&gt; &lt;defs style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"&gt; &lt;pattern id="mygrid" width="10" height="10" patternunits="userSpaceOnUse"&gt; &lt;polygon points="5,0 10,10 0,10" stroke="black"&gt;&lt;/polygon&gt; &lt;/pattern&gt; &lt;pattern id="6A35489A-D006-4344-B2A5-C3899E2C21F4" x="0" y="0" patternUnits="userSpaceOnUse" height="1" width="1" patternTransform="matrix(1,0,0,1,0,0) translate(9.925405384842906,10)" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"&gt; &lt;image x="0" y="0" xlink:href="#mygrid" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"&gt;&lt;/image&gt; &lt;/pattern&gt; &lt;/defs&gt; &lt;circle cx="60" cy="60" r="50" fill="url(#6A35489A-D006-4344-B2A5-C3899E2C21F4)" stroke="#000" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"&gt;&lt;/circle&gt; &lt;/svg&gt; &lt;/div&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload