Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As described in the <a href="http://www.w3.org/TR/SVG/animate.html#SetElement" rel="nofollow">SVG 1.1 Specification</a>:</p> <blockquote> <p>The ‘set’ element provides a simple means of <strong>just setting</strong> the value of an attribute <strong>for a specified duration</strong>.<br> …<br> <code>to = "&lt;value&gt;"</code> Specifies the value for the attribute <strong>during the duration of the ‘set’ element</strong>.</p> </blockquote> <p>(Emphasis mine.)</p> <p>As you can see, the <code>duration</code> of the <code>&lt;set&gt;</code> element is not a transition time, but rather how long the effect is to be applied. If you remove the <code>end</code> attribute you'll see the color change from red to green for 1 second <a href="http://jsfiddle.net/4xx5p/1/" rel="nofollow">and then revert</a> to the original value.</p> <p>For more details, read about the <code>&lt;set&gt;</code> element in the <a href="http://www.w3.org/TR/2001/REC-smil-animation-20010904/#setElement" rel="nofollow">SMIL Specification</a>.</p> <hr> <p><strong>Edit</strong>: Here's an example of using custom data to annotate your SVG elements and a run-once script that uses that data to create the <code>&lt;animate&gt;</code> elements you want, based on the fill of the elements. You can view this example live at <a href="http://phrogz.net/svg/change-color-on-hover.svg" rel="nofollow">http://phrogz.net/svg/change-color-on-hover.svg</a></p> <pre><code>&lt;svg xmlns="http://www.w3.org/2000/svg" xmlns:y="yasashiku" viewBox="0 0 240 150"&gt; &lt;title&gt;Change Color on Hover&lt;/title&gt; &lt;style&gt; circle { stroke:black; stroke-width:2px } circle:not([fill]) { fill:purple } &lt;/style&gt; &lt;circle cx="50" cy="50" r="40" fill="red" y:hoverAnimFillTo="blue" y:hoverAnimDur="0.3s" /&gt; &lt;circle cx="100" cy="100" r="40" fill="red" y:hoverAnimFillTo="green" y:hoverAnimDur="1s" /&gt; &lt;circle cx="150" cy="42" r="40" fill="orange" y:hoverAnimFillTo="yellow" /&gt; &lt;circle cx="200" cy="100" r="40" y:hoverAnimFillTo="steelblue" /&gt; &lt;script&gt; var els = document.getElementsByTagName('*'), y = 'yasashiku'; for (var i=els.length;i--;){ var fillColor = els[i].getAttributeNS(y,'hoverAnimFillTo'); if (fillColor){ var dur = els[i].getAttributeNS(y,'hoverAnimDur') || '0.1s'; createOn(els[i],'animate',{ begin:'mouseover', attributeType:'CSS', attributeName:'fill', to:fillColor, dur:dur, fill:'freeze' }); createOn(els[i],'animate',{ begin:'mouseout', attributeType:'CSS', attributeName:'fill', to:els[i].getAttribute('fill') || computedStyle(els[i],'fill'), dur:dur, fill:'freeze' }); } } function createOn(el,name,attrs){ var e = el.appendChild(document.createElementNS(el.namespaceURI,name)); for (var name in attrs) e.setAttribute(name,attrs[name]); return e; } function computedStyle(el,name){ return document.defaultView.getComputedStyle(el,null)[name]; } &lt;/script&gt; &lt;/svg&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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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