L
L
lavezzi12016-06-21 12:23:29
JavaScript
lavezzi1, 2016-06-21 12:23:29

Svg icons in SPA?

Hello! More recently, I began to understand and work with single page app, hence the question, how to work with svg icons? What is the best way to pack them?
I like this approach:

define all the icons inside the tag in SVG, but hide them. Then refer to each when needed using the element, referencing with xlink:href="#id"

But how will it work in SPA?
– Do not offer a web font, pliz.
-The most important thing you need is access to change this swgeshki. Hover is all that.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
L
lnked, 2016-06-21
@lnked

I wrote a gulp plugin for this that does the insertion and processing for me svgstore

R
Rafael™, 2016-06-21
@maxminimus

another option is base64

N
Nikolay Talanov, 2016-06-21
@Ronnie_Gardocki

SVG does not support dynamic change of the xlink:href attribute, so for such icons you need to write a separate mini-component that will simply dynamically insert an element with a link inside into the page. So, according to the results, it will be even easier, because you can attach a bunch of your custom attributes to this component, so that later the whole thing can be easily styled, without forcing yourself at every step to stuff a wretched design in the form

<svg>
  <use blah blah>
</svg>

Well, for IE9+ support, use this https://github.com/Keyamoon/svgxuse (just plugged into the page and everything works).
Here is an article on icons in React - https://www.sitepoint.com/a-working-svg-workflow-f...
It contains a description of my approach in the comments (especially point 4) - https://www. sitepoint.com/a-working-svg-workflow-f...

Q
qtuz, 2016-10-31
@qtuz

Look towards svg-sprite-loader .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question