Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One of the way to get a scripted background SVG working, is to use CSS4 <a href="https://developer.mozilla.org/en-US/docs/CSS/element" rel="nofollow"><code>element()</code></a>. It's currently only implemented in Firefox 4+ via <code>-moz-element()</code>.</p> <p><a href="http://jsfiddle.net/2DUuH/4/" rel="nofollow">An example:</a></p> <pre><code>&lt;div id="bg" style="width: 400px; height: 400px;"&gt; &lt;svg width="400" height="400" viewPort="0 0 400 400"&gt; &lt;!-- force correct 0,0 coordinates --&gt; &lt;rect x="0" y="0" width="1" height="1" fill="transparent" /&gt; &lt;rect x="0" y="0" id="animable1" width="120" height="120" fill="blue" /&gt; &lt;rect x="0" y="0" id="animable2" width="60" height="60" fill="red" /&gt; &lt;/svg&gt; &lt;/div&gt; &lt;div id="target" style="border: 4px dashed black; height: 400px; width: 400px; background: gray -moz-element(#bg); background-size: 20%;"&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; var divTarget = document.getElementById("target"); var animable1 = document.getElementById("animable1"); var animable2 = document.getElementById("animable2"); document.addEventListener("mousemove", function(event){ var rotation = Math.atan2(event.clientY, event.clientX); animable1.setAttribute("transform", "translate(140 140) rotate(" + (rotation / Math.PI * 360) + " 60 60)"); animable2.setAttribute("transform", "translate(170 170) rotate(" + (360 - rotation / Math.PI * 360) + " 30 30)"); }, false); animable1.setAttribute("transform", "translate(140 140) rotate(0 60 60)"); animable2.setAttribute("transform", "translate(170 170) rotate(0 30 30)"); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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