简体   繁体   中英

Javascript: Using font icons in svg's. How do I use “\u”?

I am using font icons generated by icomoon.com and displaying them as svg text using Raphael .

Basically, I have icons like these:





%

I have been inserting them into my code like so:

paper.text(x, y, iconString).attr({
   'text-anchor': 'end', 
   'font-family':'myFont', 
   'font-size':12})

BUT, in order for me to get this to work, I've had to use the Javascript way to show icons, but I don't really know enough about it to know what I'm doing wrong. For example:

iconString = "\ue005"; //This is for icon "". Works!
iconString = "\uf331"; //This is for icon "". Works!
iconString = "\ue0c1"; //This is for icon "". Works!
iconString = "\uf003"; //This is for icon "". Works!
iconString = "\u25"; //This is for icon "%". DOES NOT WORK!

So I've just been replacing "&#x" with "\\u\u0026quot; and it has been working... but not when it is short. :/ How do I do this?

I've also used the whole string (like "" , but that has only been working in text and not svg for me.)

Any ideas? Thanks!

\\u\u003c/code> requires four digits.

iconString = "\u0025";

Alternatively, two-digit numbers can also be done like so:

iconString = "\x25";

Alternatively alternatively, you can just use the plain character:

iconString = "%";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM