javascript - Use CSS to animate the fill of an SVG along the path -
i've seen lots of questions , answers how full object animation of color here. however, possible animate sharp, moving color block through fill (interior of path)? how 1 go animating svg that?
there couple javascript libraries can into: svgjs or snap.svg....should point in right direction.
just quick piece of code shw how snap work. give senario want change fill of svg on hover.
<svg id="targetsvg" ...> <!-- path forming upper shell --> <g> <path id="1" fill="#000" d="..."/> <path id="2" fill="#fff" d="..."/> <path id="3" fill="#000" d="..."/> </g> </svg> javascript
//select svg want have effect on s = snap("#targetsvg"); s.select("g").hover( ishover, idhoverout ); function ishover() { this.selectall('path').foreach( function( el ){ el.attr({ class: 'fadein' }) } ); }; function ishoverout() { this.selectall('path').foreach( function( el ){ el.attr({ class: 'fadeout' }) } ); }; css styles
.fadein { transition: fill 1s linear; fill:blue; } .fadeout { transition: fill 1s linear; }
Comments
Post a Comment