paint-brush
How to use Sass string replacement to animate changes in an SVGby@stuartjnelson
3,227 reads
3,227 reads

How to use Sass string replacement to animate changes in an SVG

by Stuart Nelson4mFebruary 5th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Sometimes I want to have an SVG as a URL-encoded <code class="markup--code markup--p-code">background-image: url(path/to/your.svg);</code>&nbsp;, often on a pseudo element (<a href="https://codepen.io/tigt/post/optimizing-svgs-in-data-uris" target="_blank">see Taylor Hunters article about URL-encoding an SVG</a>). I love doing it this way, as it means my SVG is then inside my stylesheets and saves me an additional server request. I use Sass to run a string replacement function to edit the SVG’s code and therefore animate it. Pretty cool right?! Here’s an example of how to apply this technique to a simple SVG that has a single fill color.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - How to use Sass string replacement to animate changes in an SVG
Stuart Nelson HackerNoon profile picture
Stuart Nelson

Stuart Nelson

@stuartjnelson

L O A D I N G
. . . comments & more!

About Author

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Contao