Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery, SVG: How to animate an attribute value (not style property)?
    primarykey
    data
    text
    <p>I need to animate an attribute of an SVG element, which has no CSS counterpart - <code>&lt;circle cx="..." /&gt;</code> How can I achieve that?</p> <p>Or, I can use an alternative, e.g. if I could animate <code>&lt;g/&gt;</code> using CSS's <code>top</code> or similar.</p> <p>Any experience?</p> <p>Thanks, Ondra</p> <p>Note this is not a duplicate of <a href="https://stackoverflow.com/questions/911357/how-can-i-animate-an-attribute-value-not-style-property-with-jquery">How can I animate an attribute value (not style property) with jQuery?</a> since that's about HTML.</p> <p>See also <a href="https://stackoverflow.com/questions/2294801/jquery-under-svg">jQuery under SVG</a></p> <h2><strong><em>Update</em></strong></h2> <p>In the end, I did a manual animation as in <a href="https://stackoverflow.com/questions/1108480/svg-draggable-using-jquery-and-jquery-svg">SVG draggable using JQuery and Jquery-svg</a> .</p> <p><strong>jQuery solution still welcome.</strong></p> <p>Anyway, that brought me to other problem - units mismatch. <code>evt.clientX</code> is in pixels, but <code>circle.cx.baseVal.value</code> is in some relative units. So when I do</p> <pre><code> onmousedown=" this.moving=true; this.pt0 = {x: evt.clientX, y: evt.clientY}; this.origPos = {x: this.cx.baseVal.value, y: this.cy.baseVal.value}; " onmouseup="this.moving=false;" onmouseout="this.moving=false;" onmouseover="this.moving=false;" onmousemove="if( this.moving ){ this.cx.baseVal.value = this.origPos.x + (evt.clientX - this.pt0.x); } </code></pre> <p>And have <code>&lt;embed&gt;</code> 3x larger than the SVG's "own" size, then the circle moves 3x faster than the pointer. </p> <h2><strong><em>Update</em></strong></h2> <p>I even tried </p> <pre><code>this.origPos = { x: this.cx.baseVal.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX), y: this.cy.baseVal.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX) }; ... this.cx.baseVal.newValueSpecifiedUnits( SVGLength.SVG_LENGTHTYPE_PX, this.origPos.x + (evt.clientX - this.pt0.x) ); </code></pre> <p>But <code>convertToSpecifiedUnits()</code> returns <code>undefined</code>, which seems to be a lack in implementation of <a href="http://www.w3.org/TR/SVG/types.html#InterfaceSVGLength" rel="nofollow noreferrer">http://www.w3.org/TR/SVG/types.html#InterfaceSVGLength</a> .</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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