Tuesday, November 26, 2013

SVG - XML based vector graphics to replace GIFs and PNGs


While doing UI design I faced problems with animated spinners, which I created in GIF format. One problem is I have to place spinning images on top of differently colored tiles, on various colors, which I cannot control. And second is the tiles are scalable, and the animated GIFs should scale as well. But they don't.

These issues though can be addressed by SVG format, which is supported by all major browsers except Internet Explorer (of course). IE doesn't understand animation in SVG.

(Note: if the SVG graphics doesn't work on this page as described, or for any other reason, you can visit a standalone demo page. On that demo page instead of <embed> tag I use <img>, which in the case of simple SVG animation works exactly the same. However to render it properly in Blogger posts I have to use either <embed> or <object> tags.)
Notice rough edges, and scaling quality loss on the last tile:

Well, with one compatibility issue: animation doesn't work in any version of Internet Explorer. Let's see what else we can do with SVG format.




Mouseover (achieved by CSS inside of SVG file)


Blur

All the non-animated SVG above are rendered as designed in all major browsers today. There are issues with animation in Firefox and Opera, but workarounds are possible. All css styling and scripting are inside of SVG files. SVG graphics was created in Adobe Illustrator, and then edited in text editor.