{"id":4264,"date":"2014-07-10T18:03:31","date_gmt":"2014-07-10T10:03:31","guid":{"rendered":"http:\/\/www.zhangxinxu.com\/wordpress\/?p=4264"},"modified":"2019-11-04T14:27:13","modified_gmt":"2019-11-04T06:27:13","slug":"introduce-svg-sprite-technology","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2014\/07\/introduce-svg-sprite-technology\/","title":{"rendered":"\u672a\u6765\u5fc5\u70ed\uff1aSVG Sprites\u6280\u672f\u4ecb\u7ecd"},"content":{"rendered":"<p>by <a href=\"http:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"http:\/\/www.zhangxinxu.com\/\">http:\/\/www.zhangxinxu.com<\/a><br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=4264\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=4264<\/a><\/p>\n<h3>\u4e00\u3001Sprite\u6280\u672f<\/h3>\n<p>\u8fd9\u91cc\u6240\u8bf4\u7684Sprite\u6280\u672f\uff0c\u6ca1\u9519\uff0c\u7c7b\u4f3c\u4e8eCSS\u4e2d\u7684Sprite\u6280\u672f\u3002\u56fe\u6807\u56fe\u5f62\u6574\u5408\u5728\u4e00\u8d77\uff0c\u5b9e\u9645\u5448\u73b0\u7684\u65f6\u5019\u51c6\u786e\u663e\u793a\u7279\u5b9a\u56fe\u6807\u3002<\/p>\n<p>\u53e6\uff0c\u672c\u6587\u56fe\u7247\u751a\u591a\uff0c\u722a\u673a\u515a\u7ee7\u7eed\u6d4f\u89c8\u9700\u614e\u91cd\u3002<\/p>\n<h3>\u4e8c\u3001SVG Sprites\u4e0esymbol\u5143\u7d20<\/h3>\n<p>\u76ee\u524d\uff0cSVG Sprite\u6700\u4f73\u5b9e\u8df5\u662f\u4f7f\u7528<code>symbol<\/code>\u5143\u7d20\u3002<code>symbol<\/code>\u5143\u7d20\u662f\u4ec0\u4e48\u5462\uff1f\u5355\u7eaf\u7ffb\u8bd1\u7684\u8bdd\uff0c\u662f\u201c\u7b26\u53f7\u201d\u7684\u610f\u601d\u3002\u7136\uff0c\u8fd9\u4e2a\u91ca\u4e49\u5e76\u4e0d\u7b26\u5408\u8fd9\u91cc\u7684\u573a\u666f\u3002\u4e0d\u77e5\u5927\u5bb6\u6709\u6ca1\u6709\u7528\u8fc7Flash\uff0c<code>symbol<\/code>\u5b9e\u9645\u4e0a\u5c31\u7c7b\u4f3c\u4e8eFlash\u4e2d\u7684\u201c\u5f71\u7247\u526a\u8f91\u201d\u3001\u6216\u8005\u201c\u5143\u4ef6\u201d\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u6211\u4e2a\u4eba\u89c9\u5f97\uff0c<code>symbol<\/code>\u5e94\u8be5\u89e3\u91ca\u4e3a\u201c\u5143\u4ef6\u201d\u6700\u4e3a\u6070\u5f53\uff01<\/p>\n<p>\u90a3\uff0c<code>symbol<\/code>\u548cSVG Sprite\u53c8\u6709\u4ec0\u4e48\u5173\u7cfb\u5462\uff1f<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u628aSVG\u5143\u7d20\u770b\u6210\u4e00\u4e2a\u821e\u53f0\uff0c\u800c<code>symbol<\/code>\u5219\u662f\u821e\u53f0\u4e0a\u4e00\u4e2a\u4e00\u4e2a\u7ec4\u88c5\u597d\u7684\u5143\u4ef6\uff0c\u8fd9\u8fd9\u4e9b\u4e00\u4e2a\u4e00\u4e2a\u7684\u5143\u4ef6\u5c31\u662f\u6211\u4eec\u5373\u5c06\u4f7f\u7528\u7684\u4e00\u4e2a\u4e00\u4e2aSVG\u56fe\u6807\u3002<\/p>\n<p>\u4e8e\u662f\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u96c6\u5408\u4e86\u4e09\u4e2aSVG\u56fe\u6807\u7684SVG\u5143\u7d20\u7684\u4ee3\u7801\u7ed3\u6784\u4f1a\u662f\u8fd9\u6837\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>\r\n&lt;svg>\r\n    &lt;symbol>\r\n        <span style=\"color:green;\">&lt;!-- \u7b2c1\u4e2a\u56fe\u6807\u8def\u5f84\u5f62\u72b6\u4e4b\u7c7b\u4ee3\u7801 --><\/span>\r\n    &lt;\/symbol>\r\n    &lt;symbol>\r\n        <span style=\"color:green;\">&lt;!-- \u7b2c2\u4e2a\u56fe\u6807\u8def\u5f84\u5f62\u72b6\u4e4b\u7c7b\u4ee3\u7801 --><\/span>\r\n    &lt;\/symbol>\r\n    &lt;symbol>\r\n        <span style=\"color:green;\">&lt;!-- \u7b2c3\u4e2a\u56fe\u6807\u8def\u5f84\u5f62\u72b6\u4e4b\u7c7b\u4ee3\u7801 --><\/span>\r\n    &lt;\/symbol>\r\n&lt;\/svg>\r\n<\/pre>\n<\/div>\n<p>\u6bcf\u4e00\u4e2a<code>symbol<\/code>\u5c31\u662f\u4e00\u4e2a\u56fe\u6807\u5143\u4ef6\uff0c\u4f46\u662f\uff0c\u53ea\u6709\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u662f\u65e0\u6cd5\u5448\u73b0\u7c7b\u4f3c\u4e0b\u9762\u7684\u6548\u679c\u7684\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_103255.png\" width=\"489\" height=\"162\" alt=\"SVG Sprite\u7684\u6548\u679c\u56fe\" class=\"mt10\" \/><\/p>\n<p>\u4e3a\u4f55\uff1f<\/p>\n<p>\u56e0\u4e3a\uff0c\u821e\u53f0\u4e0a\u53ea\u662f\u653e\u7f6e\u4e86\u56fe\u6807\uff0c\u5982\u679c\u4f60\u4e0d\u4f7f\u7528(use)\uff0c\u662f\u770b\u4e0d\u89c1\u7684\u3002\u5c31\u597d\u6bd4\u4f60\u5973\u670b\u53cb\u4e70\u4e86\u51e0\u7bb1\u7684\u8863\u670d\u653e\u5bb6\u91cc\uff0c\u5982\u679c\u4e0d\u7a7f\u51fa\u53bb\uff0c\u8c01\u77e5\u9053\u5979\u8fd9\u4e48\u571f\u8c6a\u5462\uff1f<\/p>\n<p>\u56e0\u6b64\uff0c\u8fd8\u5dee\u4e00\u4e2a\u201c\u4f7f\u7528\u201d\uff0c\u4e5f\u5c31\u662fSVG\u4e2d\u7684<code>&lt;use&gt;<\/code>\u5143\u7d20\u3002<\/p>\n<h3>\u4e09\u3001SVG\u4e2d\u7684use\u5143\u7d20<\/h3>\n<p><a href=\"http:\/\/tutorials.jenkov.com\/svg\/use-element.html\">use\u5143\u7d20<\/a>\u662fSVG\u4e2d\u975e\u5e38\u5f3a\u5927\uff0c\u975e\u5e38\u91cd\u8981\u7684\u4e00\u4e2a\u5143\u7d20\uff0c\u5c24\u5176\u5728Web\u5f00\u53d1\u4e2d\uff0c\u4e3a\u4f55\uff1f<\/p>\n<p>\u4e24\u70b9\uff1a<\/p>\n<ol>\n<li>\u53ef\u91cd\u590d\u8c03\u7528\uff1b<\/li>\n<li>\u8de8SVG\u8c03\u7528\uff1b<\/li>\n<\/ol>\n<p><strong>1. \u53ef\u91cd\u590d\u8c03\u7528<\/strong><br \/>\n\u4f60\u597d\u4e0d\u5bb9\u6613\uff0c\u7528\u4e86\u51e0\u5341\u4e2a\u5750\u6807\u503c\uff0c\u597d\u4e0d\u5bb9\u6613\u7ed8\u5236\u4e86\u4e00\u4e2a\u56fe\u5f62\uff0c\u5982\u679c\u4f60\u60f3\u518d\u5f04\u4e00\u4e2a\u540c\u6837\u9020\u578b\uff0c\u4f46\u4f4d\u7f6e\u4e0d\u540c\u7684\u56fe\u5f62\u51fa\u6765\uff0c\u4f60\u4f1a\u600e\u4e48\u529e\uff1f\u2014\u2014\u518d\u590d\u5236\u4e00\u904d\u4ee3\u7801\uff1f\u522b\u8bf4\u7b11\u4e86\uff0c\uff08\u5982\u679c\u771f\u90a3\u6837\uff09SVG\u6587\u4ef6\u7684\u5c3a\u5bf8\u8d76\u5f97\u4e0a\u4e8c\u5e08\u5144\u7684\u8170\u56f4\u4e86\u3002<\/p>\n<p>\u4f7f\u7528<code>&lt;use&gt;<\/code>\u5143\u7d20\u5c31\u53ef\u4ee5\uff0c\u770b\u4e0b\u9762\u7684\u677f\u6817\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>&lt;svg&gt;\r\n  &lt;defs&gt;\r\n    &lt;g id=\"shape\"&gt;\r\n        &lt;rect x=\"0\" y=\"0\" width=\"50\" height=\"50\" \/&gt;\r\n        &lt;circle cx=\"0\" cy=\"0\" r=\"50\" \/&gt;\r\n    &lt;\/g&gt;\r\n  &lt;\/defs&gt;\r\n\r\n  &lt;use xlink:href=\"#shape\" x=\"50\" y=\"50\" \/&gt;\r\n  &lt;use xlink:href=\"#shape\" x=\"200\" y=\"50\" \/&gt;\r\n&lt;\/svg&gt;<\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f\uff08IE9+\u6d4f\u89c8\u5668\u53ef\u89c1\uff09\uff1a<br \/>\n<svg width=\"500\" height=\"100\" class=\"mt10\"> <defs>  <g id=\"shape\"> <rect x=\"0\" y=\"0\" width=\"50\" height=\"50\" \/> <circle cx=\"0\" cy=\"0\" r=\"50\" \/> <\/g>  <\/defs> <use xlink:href=\"#shape\" x=\"50\" y=\"50\" \/> <use xlink:href=\"#shape\" x=\"200\" y=\"50\" \/><\/svg><\/p>\n<p>\u9996\u5148\uff0c\u6ce8\u610f\u5230\u6ca1\u6709\uff0c<code>use<\/code>\u5143\u7d20\u662f\u901a\u8fc7<code>xlink:href<\/code>\u5c5e\u6027\uff0c\u5bfb\u627e\u8981\u4f7f\u7528\u7684\u5143\u7d20\u7684\u3002<code>#shape<\/code>\u5bf9\u5e94\u7684\u5c31\u662f<code>id<\/code>\u4e3a<code>shape<\/code>\u7684\u5143\u7d20\u3002<code>use<\/code>\u5143\u7d20\u53ef\u4ee5\u6709\u81ea\u5df1\u7684\u5750\u6807\uff0c\u4ee5\u53ca\u652f\u6301<code>transform<\/code>\u53d8\u6362\uff0c\u751a\u81f3\u53ef\u4ee5use\u5176\u4ed6<code>use<\/code>\u5143\u7d20\u3002<\/p>\n<p>\u8fd9\u91cc\uff0c\u4e24\u4e2a<code>use<\/code>\u5143\u7d20\u4f7f\u7528\u7684\u662f\u540c\u4e00\u4e2a<code>g<\/code>\u5143\u7d20\uff08\u7ec4\u5408\uff09\uff0c\u4ece\u800c\u5b9e\u73b0\u4e86\u56fe\u5f62\u7684\u91cd\u590d\u8c03\u7528\u529f\u80fd\u3002<\/p>\n<p><strong>2. \u8de8SVG\u8c03\u7528<\/strong><br \/>\nSVG\u4e2d\u7684<code>use<\/code>\u5143\u7d20\u53ef\u4ee5\u8c03\u7528\u5176\u4ed6SVG\u6587\u4ef6\u7684\u5143\u7d20\uff0c\u53ea\u8981\u5728\u4e00\u4e2a\u6587\u6863\u4e2d\u3002<\/p>\n<p>\u7d27\u63a5\u7740\u4e0a\u9762\u7684\u677f\u6817\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>&lt;svg width=\"500\" height=\"110\"&gt;&lt;use xlink:href=\"#shape\" x=\"50\" y=\"50\" \/&gt;&lt;\/svg&gt;<\/pre>\n<\/div>\n<p>\u7ed3\u679c\u4ecd\u662f\u90a3\u4e2a\u56fe\u5f62\uff1a<br \/>\n<svg width=\"500\" height=\"110\" class=\"mt10\"><use xlink:href=\"#shape\" x=\"50\" y=\"50\" \/><\/svg><\/p>\n<p>\u800c\u8fd9\u4e2a<strong>\u8de8SVG\u8c03\u7528<\/strong>\u5c31\u662f\u201cSVG Sprite\u6280\u672f\u201d\u7684\u6838\u5fc3\u6240\u5728\u3002<\/p>\n<p>\u8bd5\u60f3\u4e0b\uff0c\u6211\u4eec\u53ea\u8981\u5728\u9875\u9762\u67d0\u5904\u8f7d\u5165\u4e00\u4e2a\u5145\u6ee1Sprite(<code>symbol<\/code>)\u7684SVG\u6587\u4ef6\uff08\u6216\u76f4\u63a5<code>include<\/code> SVG\u4ee3\u7801\uff09\uff0c\u4e8e\u662f\uff0c\u5728\u9875\u9762\u7684\u4efb\u4f55\u89d2\u843d\uff0c\u53ea\u8981\u60f3\u4f7f\u7528\u8fd9\u4e2a\u56fe\u6807\uff0c\u53ea\u8981\u7b80\u5355\u8fd9\u4e00\u70b9\u4ee3\u7801\u5c31\u53ef\u4ee5\u4e86\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>&lt;svg class=\"size\"&gt;&lt;use xlink:href=\"#target\" \/&gt;&lt;\/svg&gt;<\/pre>\n<\/div>\n<p>\u56fe\u6807\u5c3a\u5bf8CSS\u63a7\u5236\uff0c\u91cc\u9762\u53ea\u6709\u4e00\u4e2a\u4ec5\u6709<code>xlink:href<\/code>\u5c5e\u6027\u7684<code>use<\/code>\u5143\u7d20\uff0cDone! \u5b8c\u6210\uff01<\/p>\n<p>\u4e5f\u5373\u662f\u8bf4\uff0c\u5728HTML\u5c42\u9762\uff0c\u56fe\u6807\u4f7f\u7528\u7684\u4ee3\u7801\u6210\u672c\uff0c\u8ddf\u4f20\u7edf\u7684CSS Sprite\u6216\u8005\u6d41\u884c\u7684<code>font-face<\/code>\u51e0\u4e4e\u65e0\u5f02\uff0c\u4ee3\u7801\u7b80\u6d01\uff0c\u800c\u4e14\u5f88\u597d\u7ef4\u62a4\u3002\u6240\u6709\u7684SVG\u56fe\u6807\u90fd\u5728\u4e00\u4e2aSVG\u6e90\u4e0a\u3002retina\u826f\u597d\uff0c\u5c3a\u5bf8\u53ef\u4efb\u610f\u62c9\u4f38\uff0c\u4e14\u989c\u8272\u53ef\u63a7\uff0c\u771f\u4e43Web\u56fe\u6807\u7684\u672a\u6765\u4e4b\u661f\u3002<\/p>\n<p>\u5439\u7684\u5634\u5df4\u90fd\u5e72\u4e86\uff0c\u4e0a\u4e2a\u7b80\u5355\u7684demo\u7ed9\u5927\u5bb6\u7785\u7785, \u6211\u5148\u53bb\u7ed9\u6c34\u6392\u6c34~~<\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a class=\"a_link\" href=\"http:\/\/www.zhangxinxu.com\/study\/201407\/svg-sprite.php\" target=\"_blank\">SVG Sprite\u4f7f\u7528\u793a\u610fdemo<\/a><\/p>\n<p>\u4ee3\u7801\u5982\u4e0b\u622a\u56fe\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_114146.png\" width=\"689\" height=\"376\" alt=\"SVG Sprite\u4f7f\u7528\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<p>\u6548\u679c\u4e3a\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_142916.png\" width=\"327\" height=\"208\" alt=\"SVG\u4f7f\u7528\u7684\u56fe\u6807\u6548\u679c\" class=\"alignnone\" \/><\/p>\n<p>\u603b\u7ed3\u4e0b\u5c31\u662f\uff1a<strong>symbol + use => SVG Sprite<\/strong><\/p>\n<p>\u8bf8\u4f4d\u4f1a\u4e0d\u4f1a\u89c9\u5f97\u672c\u6587\u7684\u5185\u5bb9\u5feb\u8981\u7ed3\u675f\u4e86\u5462\uff1f<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/108.gif\" align=\"absmiddle\"><\/p>\n<p>\u563b\u563b\u563b\u563b\uff0c\u9876\u591a\u624d<strong>1\/3<\/strong>\uff0c\u4e0b\u9762\u7684\u624d\u662f\u91cd\u70b9\uff0c\u6253\u8d77\u7cbe\u795e\uff0c\u8d70\u8d77~~<\/p>\n<h3>\u56db\u3001SVG Sprite\u5b9e\u9645\u5e94\u7528\u7684\u963b\u788d<\/h3>\n<p>\u4e24\u5927\u95ee\u9898\uff1a<\/p>\n<ol>\n<li>SVG\u56fe\u6807\u4ece\u4f55\u800c\u6765\uff1f<\/li>\n<li>SVG\u56fe\u6807\u5982\u4f55\u53d8\u6210symbol\u5e76\u6574\u5408\u5728\u4e00\u8d77\uff1f<\/li>\n<\/ol>\n<p>\u7b2c<strong>1<\/strong>\u4e2a\u95ee\u9898\uff0c<strong>SVG\u56fe\u6807\u4ece\u4f55\u800c\u6765\uff1f<\/strong><br \/>\n\u201c\u8fdc\u5728\u5929\u8fb9\u8fd1\u5728\u773c\u524d\u201d\uff0cCSS3 <code>font-face<\/code>\u7684\u9010\u6e10\u5347\u6e29\uff0c\u8ba9\u5f88\u591a<code>font-face<\/code>\u5de5\u5177\u8bde\u751f\u4e86\u3002\u4f8b\u5982\u4ee5\u524d\u6211\u4ecb\u7ecd\u8fc7\u7684\u56fd\u5916\u7684<a href=\"http:\/\/icomoon.io\" target=\"_blank\">icomoon.io<\/a>\uff0c\u6216\u8005\u56fd\u5185\u963f\u91cc\u7cfb\u7684<a href=\"http:\/\/iconfont.cn\/\" target=\"_blank\">iconfont.cn<\/a>, \u6216\u8005bootsrap 3\u7c89\u4eec\u7684<a href=\"http:\/\/www.bootcss.com\/p\/font-awesome\/\" target=\"_blank\">font-awesome<\/a><\/p>\n<p>\u8fd9\u4e9b\u56fe\u6807\u5b9e\u9645\u4e0a\u90fd\u662f\u4f7f\u7528SVG\u4f5c\u4e3a\u5a92\u4ecb\u7684\uff0c\u6240\u4ee5\uff0c\u6839\u672c\u5c31\u4e0d\u8981\u62c5\u5fc3\u201cSVG\u56fe\u6807\u4ece\u4f55\u800c\u6765\u201d\uff0c\u8fd9\u56fe\u6807\u591a\u7684\u5c31\u50cf\u725b\u9b54\u738b\u8eab\u4e0a\u7684\u8671\u5b50\u2014\u2014\u4e00\u6296\u4e00\u5927\u628a\u554a\uff01<\/p>\n<p>OK\uff0c\u5982\u4f55\u83b7\u5f97\u5462\uff1f\u76f4\u63a5\u4e0b\u8f7d\u3002\u62ff<a href=\"http:\/\/iconfont.cn\/\" target=\"_blank\">iconfont.cn<\/a>\u793a\u610f\uff0c\u70b9\u51fb\u67d0\u4e00\u56fe\u6807\u7684\u4e0b\u8f7d\u6309\u94ae\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_115935.png\" width=\"177\" height=\"206\" alt=\"\u70b9\u51fb\u4e0b\u8f7d\u56fe\u6807\" class=\"alignnone\" \/><\/p>\n<p>\u70b9\u51fb\u4e0b\u8f7dSVG:<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_115952.png\" width=\"320\" height=\"234\" alt=\"\u70b9\u51fb\u4e0b\u8f7dSVG\u6309\u94ae\" class=\"alignnone\" \/><\/p>\n<p>\u4e8e\u662f\uff0c\u6211\u4eec\u5c31\u5f97\u5230\u4e86SVG\u56fe\u6807\u5566\uff01\u5982\u679c\u4f60\u8fd8\u9700\u8981\u5176\u4ed6\u56fe\u6807\uff0c\u4e5f\u6309\u7167\u8fd9\u4e2a\u6b65\u9aa4\u4e00\u4e2a\u4e00\u4e2a\u4e0b\u8f7d\u4e0b\u6765\uff0c\u5f88\u7b80\u5355\u5427~ \u7136\u540e\u628a\u5b83\u4eec\u653e\u5728\u4e00\u4e2a\u6587\u4ef6\u5939\u4e2d\uff0c\u4ee5\u5907\u540e\u7528\u3002<\/p>\n<p>\u4e0b\u9762\u6700\u5173\u952e\u7684\u662f\u7b2c<strong>2<\/strong>\u4e2a\u95ee\u9898\uff0c<strong>\u5982\u4f55\u5408\u5e76\u8fd9\u4e9bSVG\u5230\u4e00\u4e2aSVG\u4e0a\uff1f<\/strong>\u540c\u65f6\u6ee1\u8db3\u4f7f\u7528\u7684\u662f<code>symbol<\/code>\u6807\u7b7e\uff0c\u5e76\u53ef\u4ee5\u4f7f\u7528\u88f8\u9732\u7684<code>use<\/code>\u5143\u7d20\uff08\u9664\u4e86<code>xlink:href<\/code>\u6ca1\u6709\u5176\u4ed6\u5c5e\u6027\uff09\u8c03\u7528\u5462\uff1f<\/p>\n<p>\u5f88\u957f\u5f88funny, \u8981\u4e13\u95e8\u72ec\u7acb\u4e24\u6bb5\uff0c<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/4.gif\" align=\"absmiddle\"><\/p>\n<h3>\u4e94\u3001\u5173\u4e8e\u5408\u5e76\uff1a\u504f\u5f00\u53d1\u7684\u524d\u7aef\u770b\u8fd9\u91cc<\/h3>\n<div style=\"padding:10px; border: 1px dashed #ddd;\"><strong>2018-08-19\u5f3a\u52bf\u63d2\u5165<\/strong><br \/>\n\u73b0\u5728\u662fgulp\u5929\u4e0b\u4e86\uff0c\u6240\u4ee5\u4e0b\u9762\u5185\u5bb9\u4ec5\u4f9b\u53c2\u8003\u3002\n<\/div>\n<p>\u8fd9\u91cc\u7684\u65b9\u6cd5\u9002\u7528\u4e8e\u504f\u5f00\u53d1\u7684\u524d\u7aef\uff0c\u4e00\u4e9b\u5bf9\u6307\u4ee4\u65e0\u611f\u7684\u59b9\u5b50\u4eec\uff0c\u53ef\u4ee5\u770b\u4e0b\u9762\u504f\u8bbe\u8ba1\u7684\u65b9\u6cd5\u3002<\/p>\n<p>Github\u4e0a\uff0c\u6709\u4e2a\u540d\u4e3a<code>svgstore<\/code>\u7684<code>grunt<\/code>\u63d2\u4ef6\uff0c\u5730\u5740<a href=\"https:\/\/github.com\/FWeinb\/grunt-svgstore\/\">\u6233\u8fd9\u91cc<\/a>\u3002\u5982\u679c\u60a8\u8fd8\u4e0d\u4e86\u89e3<code>grunt<\/code>, \u53ef\u4ee5\u770b\u770b\u8fd9\u4e24\u7bc7\u6211\u89c9\u5f97\u4e0d\u9519\u7684\u6587\u7ae0\uff1a\u201c<a href=\"http:\/\/www.cnblogs.com\/snandy\/archive\/2013\/03\/07\/2946989.html\">\u4f7f\u7528GruntJS\u6784\u5efaWeb\u7a0b\u5e8f (1)<\/a>\u201d\u548c\u201c<a href=\"http:\/\/www.cnblogs.com\/snandy\/archive\/2013\/03\/11\/2949177.html\">\u4f7f\u7528GruntJS\u6784\u5efaWeb\u7a0b\u5e8f (2)<\/a>\u201d.<\/p>\n<p><code>grunt<\/code>\u6539\u88c5\u7684\u88c5\u597d\u540e\uff0c\u6267\u884c\u4e0b\u9762\u7684\u6307\u4ee4\uff0c<\/p>\n<div class=\"zxx_code\">\n<pre>npm install grunt-svgstore --save-dev<\/pre>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-09_113147.png\" width=\"528\" height=\"411\" alt=\"\u5b89\u88c5grunt-svgstore\" class=\"alignnone\" \/><\/p>\n<p>\u70e7\u4e2a\u9999\u4fdd\u4f51\u5b89\u88c5\u6210\u529f\uff0c\u7136\u540e\u4f60\u5c31\u4f1a\u770b\u5230\u5728<code>node_modules<\/code>\u6587\u4ef6\u5939\u4e2d\u4e00\u4e2a\u540d\u4e3a<code>grunt-svgstore<\/code>\u7684\u5b50\u6587\u4ef6\u5939\uff08\u5982\u4e0b\uff09\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_145657.png\" width=\"329\" height=\"106\" alt=\"grunt-svgstore\u6587\u4ef6\u5939\" class=\"alignnone\" \/><\/p>\n<p>\u8fd9\u4e2a\u540d\u4e3a<code>grunt-svgstore<\/code>\u7684\u6587\u4ef6\u5939\u4e2d\u6709\u4e2a\u540d\u4e3a<code>Gruntfile.js<\/code>\u7684\u6587\u4ef6\uff0c\u636e\u6211\u4e2a\u4eba\u7406\u89e3\uff0c\u8fd9\u4e2aJS\u662f\u6240\u6709<code>grunt<\/code>\u63d2\u4ef6\u8981\u4f7f\u7528\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<p>\u6211\u5728\u91cc\u9762\u505a\u4e86\u4e00\u4ef6\u4e8b\u60c5\uff0c\u52a0\u4e86\u8fd9\u4e48\u4e00\u884c\u4ee3\u7801\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_150346.png\" width=\"498\" height=\"104\" alt=\"\u52a0\u4e86\u4e00\u884c\u4ee3\u7801\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<p>\u4e3a\u4ec0\u4e48\u8981\u52a0\u8fd9\u4e48\u884c\u4ee3\u7801\u5462\uff1f\u56e0\u4e3a<a href=\"https:\/\/github.com\/FWeinb\/grunt-svgstore\/\">grunt-svgstore<\/a>\u9879\u76eeREADME.md\u8ba9\u52a0\u7684\uff0c\u6240\u4ee5\u6211\u5c31\u52a0\u4e86 <img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/98.gif\" align=\"absmiddle\">\u3002<\/p>\n<p>\u4f60\u4f1a\u770b\u5230<\/p>\n<div class=\"zxx_code\">\n<pre>svgstore: {\r\n\r\n}<\/pre>\n<\/div>\n<p>\u4e2d\u6709\u4e00\u5927\u5806\u7684\u914d\u7f6e\u4ec0\u4e48\u7684\uff0c\u8fd9\u4e9b\u90fd\u662f\u7528\u6765\u72ec\u7acb\u6d4b\u8bd5\u5404\u4e2aAPI\u7684\uff08<code>options<\/code>\u5bf9\u8c61\u4e2d\u5404\u4e2a\u952e\u5c31\u662fAPI\u540d\u79f0\uff09\uff0c\u8ba9\u4f60\u77e5\u9053\u6b64\u63d2\u4ef6\u5404\u4e2aAPI\u90fd\u662f\u5e72\u561b\u7528\u7684\uff0c\u5177\u4f53\u91ca\u4e49\u53c2\u89c1\u8be5Github\u9879\u76ee\u3002\u5fcd\u4e0d\u4f4f\u63d0\u4e00\u4e0b\uff0c\u5982\u679c\u4f60\u5e0c\u671bSVG\u56fe\u6807\u989c\u8272\u53ef\u4ee5\u5728CSS\u4e2d\u901a\u8fc7<code>fill<\/code>\u63a7\u5236\uff0c<code>cleanup<\/code>\u8bbe\u7f6e\u4e3a<code>true<\/code>.<\/p>\n<p>OK, \u51c6\u5907\u5de5\u4f5c\u5b8c\u6bd5\uff0c\u4e0b\u9762\u6765\u5b9e\u8df5\u4e0b\u3002\u6211\u628a\u4eceiconfont.cn\u4e0a\u4e0b\u8f7d\u4e0b\u6765\u76843\u4e2aSVG\u90fd\u653e\u5728\u4e86\u4e00\u4e2a\u540d\u4e3a<code>mytest<\/code>\u7684\u6587\u4ef6\u5939\u4e0b\uff0c\u6211\u5e0c\u671b\u8fd9\u4e2a\u6587\u4ef6\u5939\u4e0b\u7684SVG\u90fd\u6574\u5408\u5728\u4e00\u8d77\uff0c\u5e76\u53ef\u4ee5\u65b9\u4fbf\u8c03\u7528\uff0c\u600e\u4e48\u529e\uff1f<\/p>\n<p>\u5728<code>svgstore: {}<\/code>\u5185\u90e8\u641e\u4e2a\u81ea\u5b9a\u4e49\u7684\u914d\u7f6e\uff0c\u89c1\u4e0b\u56fe\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_152531.png\" width=\"368\" height=\"158\" alt=\"\u81ea\u5b9a\u4e49\u7684\u914d\u7f6e\" class=\"alignnone\" \/><\/p>\n<p>\u610f\u601d\u662f\uff1a<code>mytest<\/code>\u6587\u4ef6\u5939\u4e0b\u7684\u6240\u6709SVG\u5408\u5e76\u6210\u4e00\u4e2a\u540d\u4e3a<code>mytest.svg<\/code>\u7684\u5927SVG\u6587\u4ef6\uff0c\u5e76\u653e\u5728<code>tmp<\/code>\u6587\u4ef6\u5939\u4e0b\u3002<\/p>\n<p>\u6211\u4eec<code>cd<\/code>\u5230<code>grunt-svgstore<\/code>\u76ee\u5f55\uff0c\u7136\u540e\u5728\u547d\u4ee4\u884c\u5de5\u5177\u4e2d\u8f93\u5165\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>grunt<\/pre>\n<\/div>\n<p>\u7136\u540e\u8d70\u8d77\uff0c\u518d\u70e7\u7b2c2\u6839\u9999\uff0c\u4fdd\u4f51\u4e00\u5207\u6b63\u5e38\u2026\u2026<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_153304.png\" width=\"407\" height=\"188\" alt=\"mytest\u8d70\u8d77~\" class=\"alignnone\" \/><\/p>\n<p>\u7136\u540e\uff0c\u5c31\u53ef\u4ee5\u5728tmp\u6587\u4ef6\u5939\u4e0b\u770b\u5230\u6211\u4eec\u7684\u5c0f\u7ed3\u6676\u2014\u2014<code>mytest.svg<\/code>\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u793a\u610f\u7684HTML demo\u9875\u9762\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_153059.png\" width=\"347\" height=\"76\" alt=\"SVG\u5408\u5e76\u7684\u6587\u4ef6\uff0c\u4ee5\u53ca\u5bf9\u5e94\u7684demo~\" class=\"alignnone\" \/><\/p>\n<p>\u6b64demo\u9875\u9762\u6e90\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>&lt;svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:0;height:0;visibility:hidden;\">&lt;symbol viewBox=\"0 0 1024 1024\" id=\"iconfont-baobei\">&lt;title>iconfont-baobei&lt;\/title>&lt;path fill=\"#272636\" d=\"M...z\" transform=\"translate(0, 800) scale(1, -1)\"\/>&lt;\/symbol>&lt;symbol viewBox=\"0 0 1024 1024\" id=\"iconfont-bianji\">&lt;title>iconfont-bianji&lt;\/title>&lt;path fill=\"#272636\" d=\"M...z\" transform=\"translate(0, 800) scale(1, -1)\"\/>&lt;\/symbol>&lt;symbol viewBox=\"0 0 1024 1024\" id=\"iconfont-shangchuan\">&lt;title>iconfont-shangchuan&lt;\/title>&lt;path fill=\"#272636\" d=\"M...z\" transform=\"translate(0, 800) scale(1, -1)\"\/>&lt;\/symbol>&lt;\/svg>\r\n\r\n&lt;svg>\r\n    &lt;use xlink:href=\"#iconfont-baobei\">&lt;\/use>\r\n&lt;\/svg>\r\n&lt;svg>\r\n    &lt;use xlink:href=\"#iconfont-bianji\">&lt;\/use>\r\n&lt;\/svg>\r\n&lt;svg>\r\n    &lt;use xlink:href=\"#iconfont-shangchuan\">&lt;\/use>\r\n&lt;\/svg><\/pre>\n<\/div>\n<p>\u6548\u679c\u5982\u4e0b\u622a\u56fe\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_154543.png\" width=\"236\" height=\"116\" alt=\"\u7b2c\u4e00\u6b21\u6210\u578b\u7684SVG\u6548\u679c\u56fe\" class=\"alignnone\" \/><\/p>\n<p>Oh, no! \u600e\u4e48\u6709\u6b8b\u7f3a\uff0c\u4e0d\u5b8c\u7f8e\uff0c\u611f\u89c9\u4e0d\u4f1a\u518d\u7231\u4e86\uff01<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/18.gif\" align=\"absmiddle\"><\/p>\n<p>\u6de1\u5b9a\uff0c\u5c0f\u95ee\u9898\uff0c\u8c8c\u4f3c\u662f\u8fd9\u4e9bSVG\u5236\u4f5c\u7684\u65f6\u5019\uff0c\u672c\u8eab\u6709\u4e9b\u95ee\u9898\uff08\u4e3a\u4e86font-face\u505a\u7684\u8c03\u6574\uff1f\uff09\uff0c\u6211\u4eec\u5728illustrator\u4e2d\u6253\u5f00\u8fd9\u4e9bSVG, \u4e00\u4e0b\u5b50\u5c31\u53ef\u4ee5\u770b\u51fa\u75c7\u7ed3\u6240\u5728\uff0c\u4f8b\u5982\uff0c\u7ec6\u7ec6\u7684\u94c5\u7b14\u56fe\u6807\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_103003.png\" width=\"427\" height=\"417\" alt=\"\u94c5\u7b14\u7684\u4e24\u4e2a\u89d2\u5728\u821e\u53f0\u4e4b\u5916\u4e86\" class=\"alignnone\" \/><\/p>\n<p>\u94c5\u7b14\u7684\u4e24\u4e2a\u89d2\u5728\u767d\u8272\u7684\u821e\u53f0\u4e4b\u5916\u4e86\uff0c\u6b63\u597d\u8ddf\u4e0a\u9762\u622a\u56fe\u5c11\u6389\u7684\u4e24\u4e2a\u89d2\u4e00\u81f4\u3002\u8981\u4fee\u590d\uff0c\u8d85easy, \u7b49\u6bd4\u4f8b\u7f29\u653e\u5230\u767d\u8272\u821e\u53f0\u5185\u5c31OK\u4e86\uff0cctrl+S\u4fdd\u5b58\uff0c\u7136\u540e\u91cd\u65b0\u6267\u884c\u4e0b<code>grunt<\/code>\u547d\u4ee4\u5c31\u597d\u4e86\u3002<\/p>\n<p>\u7136\u540e\uff0c\u6d4f\u89c8\u5668\u5237\u65b0\u4e0b\u521a\u521a\u7684demo\u9875\u9762\uff0c\u5f53\u5f53\u5f53\u5f53\uff0c\u6492\u82b1\u6492\u82b1~~<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_160014.png\" width=\"242\" height=\"111\" alt=\"\u6ea2\u51fa\u8c03\u6574\u540e\u7684SVG\u6548\u679c\" class=\"alignnone\" \/><\/p>\n<p>\u4ee5\u4e0a~<\/p>\n<h3>\u516d\u3001\u5173\u4e8e\u5408\u5e76\uff1a\u504f\u8bbe\u8ba1\u7684\u524d\u7aef\u770b\u8fd9\u91cc<\/h3>\n<div style=\"padding:10px; border: 1px dashed #ddd;\"><strong>2018-08-19\u5f3a\u52bf\u63d2\u5165<\/strong><\/p>\n<p>\u82b1\u4e86\u51e0\u5929\u65f6\u95f4\u505a\u4e86\u4e2aSVG\u5728\u7ebf\u538b\u7f29\u5408\u5e76\u5de5\u5177\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/sp\/svgo\/\" rel=\"noopener\" class=\"a_link\" target=\"_blank\">SVG\u5728\u7ebf\u538b\u7f29\u5408\u5e76\u5de5\u5177<\/a><\/p>\n<p>illustrator\u6216\u8005sketch\u5bfc\u51faSVG\uff0c\u6279\u91cf\u4e0a\u4f20\uff0c\u7136\u540e\u4e0b\u8f7d\u6216\u590d\u5236\u5373\u53ef\uff01<\/p>\n<p>\u672c\u6bb5\u4e0b\u9762\u5185\u5bb9\u5df2\u7ecf\u5b8c\u5168\u8fc7\u65f6\uff0c\u5927\u5bb6\u53ef\u4ee5\u76f4\u63a5\u5ffd\u7565\uff0c\u4f7f\u7528\u4e0a\u9762\u5de5\u5177\u5373\u53ef\uff01\n<\/p><\/div>\n<p>\u6ce8\u610f\uff1a<strong>\u8fd9\u91cc\u7684\u65b9\u6cd5\uff0c\u5c31\u7b97\u662fCSS\u5b8c\u5168\u4e0d\u61c2\u7684\u8bbe\u8ba1\u5e08\u4e5f\u53ef\u4ee5\u8f7b\u677e\u4e0a\u624b\uff01<\/strong><\/p>\n<p>\u5bf9\u4e8e\u4e00\u4e9b\u59b9\u5b50\uff0c\u53ea\u4f1a\u5199\u4e9b\u9875\u9762\uff0c\u5bf9\u4e8e\u5f00\u53d1\u3001\u7f16\u7a0b\u7684\u611f\u89c9\u6bd4\u51cf\u80a5\u8fd8\u96be\uff0c\u663e\u7136\uff0c\u4e0a\u9762\u7684\u504f\u5f00\u53d1\u9700\u7f16\u8bd1\u7684\u5de5\u5177\u63d2\u4ef6\u5bf9\u5979\u4eec\u5c31\u5f88\u5403\u529b\u3002\u4e0d\u6025\u4e0d\u6025\uff0c\u8fd9\u91cc\u6709\u9762\u5411\u8bbe\u8ba1\u5e08\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u4f60\u9700\u8981\u4e00\u4e2a\u7280\u5229\u7684\u8f6f\u4ef6\uff0c\u77e2\u91cf\u4e4b\u738b\uff0cillustrator!<\/p>\n<p>\u4e00\u6b65\u4e00\u6b65\u8ddf\u6211\u6765\uff1a<\/p>\n<ol>\n<li>\u6253\u5f00\u8f6f\u4ef6\uff0c\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6\uff0c\u7136\u540e\u53e6\u5b58\u4e3aSVG\u683c\u5f0f\uff1b<\/li>\n<li>\u4ece\u6807\u5c3a\u4e2d\u62c9\u51fa\u4e00\u4e9b\u53c2\u8003\u7ebf\uff0c\u641e\u4e9b\u6b63\u65b9\u5f62\u683c\u5b50\uff0c\u6211\u81ea\u5df1\u7528\u7684\u5c3a\u5bf8\u662f<code>160*160<\/code>, \u77e2\u91cf\u65e0\u5c3a\u5bf8\uff0c\u4f60\u968f\u610f\uff1b<\/li>\n<li>\u628a\u4e0b\u8f7d\u7684SVG\u56fe\u5f62\u62d6\u5230\u8fd9\u4e9b\u683c\u5b50\u4e2d\uff0c\u7f29\u653e\u5230\u5408\u9002\u5927\u5c0f\u3002\u6211\u662f\u94fa\u6ee1\u7684\uff0c\u8fd9\u6837\u7531\u4e8e\u5bf9\u6bd4\u660e\u663e\uff0c\u5404\u4e2a\u56fe\u6807\u5c3a\u5bf8\u5c31\u90fd\u662f\u4e00\u81f4\u7684\uff0cCSS\u63a7\u5236\u65b9\u4fbf\uff1b<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_161232.png\" width=\"276\" height=\"123\" alt=\"illustrator\u53c2\u8003\u7ebf\u4e0e\u56fe\u5f62\u7f29\u653e\" class=\"alignnone\" \/>\n<\/li>\n<li>\u8fd9\u4e00\u6b65\u5f88\u5173\u952e\u3002\u6253\u5f00Symbols\u9762\u677f\uff0c\u5728Window\u83dc\u5355\u680f\u4e2d\uff0c\u6216Shift+Ctrl+F11\u542f\u7528\u3002\u7136\u540e\uff0c\u62d6\u52a8\u683c\u5b50\u4e2d\u7684SVG\u56fe\u5f62\u5230\u8fd9\u4e2a\u9762\u677f\u4e2d\uff0c\u5c31\u4f1a\u89e6\u53d1\u65b0\u5efa\u201c\u5143\u4ef6\u201d\u7684\u884c\u4e3a\uff0c\u4f1a\u6253\u5f00\u7c7b\u4f3c\u4e0b\u9762\u7684\u9762\u677f\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_161756.png\" width=\"296\" height=\"327\" alt=\"illustrator\u4e2d\u65b0\u5efa\u5143\u4ef6\u7684\u9762\u677f\" class=\"alignnone\" \/><\/p>\n<p>\u5176\u4e2d\uff0c<code>name<\/code>\u5c31\u662fSVG\u4e2d\u5bf9\u5e94\u7684<code>symbol<\/code>\u5143\u7d20\u7684<code>id<\/code>\uff0c\u56e0\u6b64\uff0c\u6700\u597d\u4f7f\u7528\u82f1\u6587\uff0c\u6700\u597d\u6613\u8bc6\u522b\u3002\u4e0b\u9762\u7684<code>type<\/code>\u4f60\u968f\u610f\uff0c\u8fd9\u4e2a\u53ea\u8981\u5728SVG\u5bfc\u5165\u5230Flash\u4e2d\u4f7f\u7528\u65f6\u5019\u624d\u6709\u7528\u7684\uff0c\u8fd9\u91cc\uff0c\u6211\u4eec\u4e0d\u548cFlash\u6253\u4ea4\u9053\u3002\u7136\u540e\uff0cOK, \u8fd9\u4e2a\u56fe\u6807\u5c31\u201c\u5143\u4ef6\u201d\u5316\u4e86\uff0c\u6309\u7167\u540c\u6837\u7684\u6b65\u9aa4\uff0c\u8ba93\u4e2a\u56fe\u6807\u90fd\u53d8\u6210\u5143\u4ef6\uff08\u4ee5\u540e\u53ef\u91cd\u590d\u4f7f\u7528\uff09\uff0cSymbols\u9762\u677f\u4f1a\u7c7b\u4f3c\u4e0b\u9762\u8fd9\u6837\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_162242.png\" width=\"261\" height=\"150\" alt=\"Symbols\u9762\u677f\u622a\u56fe\" class=\"alignnone\" \/><\/li>\n<li>Ctrl+S\u4fdd\u5b58\uff0c\u5408\u5e76\u597d\u7684SVG\u5373\u51fa\u7089\u3002\u6211\u4eec\u76f4\u63a5\u5728\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00\u6b64SVG\uff0c\u6548\u679c\u4e0d\u9519\u54e6~<br \/>\n<img loading=\"lazy\" decoding=\"async\" width=\"245\" height=\"81\" alt=\"SVG Sprite\u7684\u6548\u679c\u56fe\" class=\"mt10\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_103255.png\">\n<\/li>\n<\/ol>\n<p>\u662f\u4e0d\u662f\u5c31\u8fd9\u4e48\u7ed3\u675f\u4e86\uff0c\u592a\u5929\u771f\u4e86\u3002\u4eba\u751f\u4e0d\u5982\u610f\u4e8b\u5341\u4e4b\u516b\u4e5d\u3002\u6211\u4eec\u7785\u4e00\u7785SVG\u7684\u6e90\u4ee3\u7801\uff0c\u4f1a\u53d1\u73b0\uff0c<code>use<\/code>\u5143\u7d20\u5c45\u7136\u8ddf\u5c0f\u9f99\u5973\u4e00\u6837\uff0c\u4e0d\u5e72\u51c0\u7eaf\u6d01\u5566\u2014\u2014\u4e0a\u9762\u4e00\u5927\u63a8\u4e71\u4e03\u516b\u7cdf\u7684\u5c5e\u6027\uff01<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_162911.png\" width=\"579\" height=\"56\" alt=\"use\u5143\u7d20\u4e0a\u5927\u628a\u4e71\u4e03\u516b\u7cdf\u5c5e\u6027\" class=\"alignnone\" \/><\/p>\n<p>\u96be\u9053\u6211\u4eec\u8981\u5728\u7f51\u9875\u4e2d\u4f7f\u7528\u5982\u6b64\u81c3\u80bf\u7684<code>use<\/code>\u5143\u7d20\u5417\uff1f<\/p>\n<p>\u6211\u4ee5\u5c0f\u65b0\u7684\u660e\u4e49\u544a\u8bc9\u4f60\uff0c\u7edd\u5bf9\u4e0d\u4f1a\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/kaokaoni.jpg\" width=\"234\" height=\"220\" alt=\"\u5c0f\u65b0\u7684\u540d\u4e49\" class=\"alignnone\" \/><\/p>\n<p>\u56e0\u4e3a\u6211\u6628\u665a\u5728\u5bb6\u6298\u817e\u51fa\u4e86\u4e2a\u5de5\u5177\uff0c\u53ef\u4ee5\u5c06illustrator\u751f\u6210SVG\u8f6c\u6362\u6210web\u53ef\u7528SVG Sprite. <\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/sp\/svg.html\" class=\"a_link\" target=\"_blank\">illustrator\u751f\u6210SVG\u8f6c\u6362\u6210web\u53ef\u7528SVG Sprite\u5de5\u5177demo<\/a><\/p>\n<p>\u4e0a\u5de5\u5177\u5b8c\u6574\u5730\u5740\u662f\uff1ahttp:\/\/www.zhangxinxu.com\/sp\/svg.html  \u5f88\u597d\u8bb0\u5fc6\uff0c\u6211\u7ad9\u70b9<code>\u57df\u540d+sp+svg.html<\/code>, <code>sp<\/code>\u662f<code>special<\/code>\u7684\u7f29\u5199\uff0c\u4e13\u95e8\u653e\u5de5\u5177\u7528\u7684\u3002<\/p>\n<p>\u4f7f\u7528\u5f88\u7b80\u5355\uff1a<\/p>\n<ol>\n<li>\u628aillustrator\u751f\u6210SVG\u6240\u6709\u4ee3\u7801\u62f7\u8d1d\u5230\u7b2c\u4e00\u4e2a\u6846\u6846\u91cc\uff1b<\/li>\n<li>\u70b9\u51fb\u201c\u8f6c\u6362\u840c\u840c\u54d2\u201d\u6309\u94ae\uff0c\u9002\u7528\u4e8eSVG Sprite\u6280\u672f\u7684\u65b0\u4ee3\u7801\u5c31\u51fa\u6765\u4e86\uff08\u5de6\u4e0b\u7684\u6846\u6846\uff09\uff1b\u540c\u65f6\uff0c\u53f3\u4fa7\u663e\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u8be5SVG Sprite\u5728web\u4e2d\u771f\u5b9e\u5b9e\u8df5\uff1b<\/li>\n<li>\u5de6\u4e0b\u89d2\u8fd8\u6709\u4e2a\u7ea2\u8272\u7684\u201c\u5bfc\u51fa\u8be5SVG\u201d\uff0c\u5c31\u662f\u5b57\u9762\u610f\u601d\uff0c\u53ef\u4ee5\u81ea\u5b9a\u4e49\u540d\u79f0\uff0c\u4e5f\u53ef\u4f7f\u7528\u968f\u673a\u540d\u79f0\uff0c\u4e3a\u7a7a\u5373\u53ef\uff1b<\/li>\n<\/ol>\n<p>\u4e00\u5f00\u59cb\u7684<a class=\"a_link\" href=\"http:\/\/www.zhangxinxu.com\/study\/201407\/svg-sprite.php\" target=\"_blank\">SVG Sprite\u4f7f\u7528\u793a\u610fdemo<\/a>\u5c31\u662f\u4f7f\u7528\u8fd9\u4e2a\u5de5\u5177\u751f\u6210\u7684\u54e6~ \u89c1\u4e0b\u7f29\u7565\u56fe\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_164625.png\" width=\"579\" height=\"449\" alt=\"illustrator\u751f\u6210SVG\u8f6c\u6362\u5de5\u5177\u4f7f\u7528\u622a\u56fe\" class=\"alignnone\" \/><\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong>\u6b64\u5de5\u5177\u503c\u9002\u7528\u4e8eillustrator\u751f\u6210\u7684SVG, \u6c34\u5e73\u6709\u9650\uff0c\u5176\u4ed6SVG\u8f6c\u6362\u5341\u6709\u516b\u4e5d\u4f1a\u8ddb\u6389\u3002\u6ca1\u600e\u4e48\u6d4b\u8bd5\uff0c\u5982\u679c\u53d1\u73b0\u6b64\u5de5\u5177\u8f6c\u6362\u51fa\u4e86\u95ee\u9898\uff0c\u6b22\u8fce\u63d0\u9192\uff0c\u5b9a\u4f1a\u53ca\u65f6\u4fee\u590d\u3002\u53e6\u5916\uff0c\u751f\u6210\u7684SVG\u6587\u4ef6\u4f1a\u4e0d\u5b9a\u671f\u6e05\u7406\uff0c\u8bf7\u52ff\u5916\u94fe\u3002<\/p>\n<p>\u6211\u60f3\u60f3\uff0c\u8fd8\u6709\u6ca1\u6709\u4ec0\u4e48\u95ee\u9898\u2026\u2026\u54e6\uff0c\u4e3a\u4ec0\u4e48\u8bf4\u6b64\u65b9\u6cd5\u4e0eCSS Sprite\u8fd8\u8981\u7b80\u5355\u3002<\/p>\n<p>\u56e0\u4e3a\uff0cCSS Sprite\u8fd8\u9700\u8981\u5728CSS\u4e2d\u4f7f\u7528<code>background-position<\/code>\u4e00\u4e2a\u4e00\u4e2a\u5730\u5b9a\u4f4d\uff0c\u54e6\uff0c\u5929\u54ea~ \u5982\u679c\u6ca1\u6709\u5de5\u5177\u7684\u8bdd\uff0c\u5c31\u7eaf\u7cb9\u642c\u7816\u7684\u82e6\u529b\u6d3b\u554a~<\/p>\n<p>\u4f46\u662f\uff0c\u8fd9\u91cc\u7684SVG Sprite\u7684\u5b9a\u4f4d\uff0c\u4f60\u53ea\u8981\u5728illustrator\u4e2d\u628a\u4f4d\u7f6e\u653e\u597d\uff0cillustrator\u8fd9\u4e2a\u8f6f\u4ef6\u5c31\u81ea\u52a8\u5e2e\u4f60\u5b9a\u4f4d\u597d\u4e86\u3002\u4f60\u53ea\u8981\u5728\u6211\u7684\u5de5\u5177\u4e2d\u8f6c\u6362\u4e0b\uff0c\u751f\u6210\u4e0b\uff0c\u7136\u540e\u5728\u9700\u8981\u4f7f\u7528\u7684\u5730\u65b9\u4f7f\u7528\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>&lt;svg&gt;&lt;use xlink:href=\"#target\" \/&gt;&lt;\/svg&gt;<\/pre>\n<\/div>\n<p>\u5c31\u597d\u4e86\uff0c\u7528\u5230CSS\u4e86\u5417\uff1f\u51e0\u4e4e\u6ca1\u6709\uff0c\u9664\u4e86\u5bf9SVG\u505a\u5c3a\u5bf8\u9650\u5236\u4ee5\u53ca\u6539\u53d8\u56fe\u6807\u7684\u989c\u8272\u3002OK\uff0c\u8fd9\u70b9\u7a0b\u5ea6\u7684\u4e1c\u897f\uff0c\u5c0f\u767d\u8bbe\u8ba1\u5e08\u4e5f\u53ef\u4ee5\u8f7b\u677e\u4e0a\u624b\u3002<\/p>\n<p>\u4ece\u8fd9\u4e00\u70b9\u6765\u770b\uff0cSVG\u53c8\u4e00\u6b21\u6210\u4e3a\u4e86\u660e\u65e5\u4e4b\u661f\uff01\u8bbe\u8ba1\u5e08\u53ea\u8981\u5728illustrator\u4e2d\u505a\u597d\u56fe\u5c31\u53ef\u4ee5\u4e86\uff0c\u5b8c\u5168\u6ca1\u6709\u4ece\u524d\u90a3\u79cd\u5e2e\u91cd\u6784\u5207\u56fe\u7684\u82e6\u903c\u7ecf\u5386\u4e86\uff0c\u662f\u4e0d\u662f\u8981\u5564\u9152\u70b8\u9e21\u5e86\u795d\u4e0b\uff01 <img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/101.gif\" align=\"absmiddle\"><\/p>\n<p><strong>\u8865\u5145\u4e8e2014\u5e747\u670814\u65e5<\/strong><br \/>\nIcoMoon\u76ee\u524d\u53ef\u4ee5\u76f4\u63a5\u8f6c\u6362\u6210SVG Sprite.<\/p>\n<ol>\n<li>\u8fdb\u5165 <a href=\"http:\/\/icomoon.io\/app\/\">http:\/\/icomoon.io\/app\/<\/a><\/li>\n<li>\u70b9\u51fb&#8221;import icons&#8221;\u6309\u94ae\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-14_143338.png\" width=\"219\" height=\"90\" alt=\"\u6dfb\u52a0\u56fe\u6807\u6309\u94ae\" class=\"alignnone\" \/><\/li>\n<li>\u9009\u62e9\u9700\u8981\u7684\u56fe\u6807\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-14_143348.png\" width=\"367\" height=\"190\" alt=\"\u9009\u62e9\u9700\u8981\u7684\u56fe\u6807\" class=\"alignnone\" \/><\/li>\n<li>\u70b9\u51fb\u9875\u9762\u4e0b\u9762\u56fa\u5b9a\u7684SVG\u6309\u94ae\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-14_143402.png\" width=\"237\" height=\"96\" alt=\"SVG\u6309\u94ae\" class=\"alignnone\" \/><\/li>\n<li>\u70b9\u51fb\u6253\u5f00\u7684\u5f39\u6846\u7684download\u6309\u94ae\u5373\u53ef\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-14_143434.png\" width=\"628\" height=\"310\" alt=\"\u4e0b\u8f7dSVG Sprite\u5f39\u6846\u4ee5\u53ca\u6309\u94ae\" class=\"alignnone\" \/><\/li>\n<li>\u4e0b\u8f7d\u7684\u6e90\u6587\u4ef6\u4e2d\uff0c\u6709\u4e24\u4e2a\u6587\u4ef6\u5939\uff0c\u5176\u4e2dsprites\u6587\u4ef6\u5939\u4e2d\uff0c\u6709\u5408\u5e76\u597d\u7684SVG, png\u56fe\u6807\u4ee5\u53ca\u5bf9\u5e94\u7684demo, \u8fd9\u4e2a\u7edd\u4e0d\u4f1a\u8ff7\u8def\u7684\uff0c\u5c31\u4e0d\u622a\u56fe\u5c55\u793a\u4e86\u3002<\/li>\n<\/ol>\n<p>\u561b\uff0c\u5c31\u6b64\u770b\u6765\uff0c\u8fd9\u91cc\u624d\u662f\u8001\u5c11\u7686\u5b9c\uff0cSVG Sprites\u6574\u5408\u6700\u5bb9\u6613\u7684\u5730\u65b9\u3002\u4e0d\u8fc7\uff1a<\/p>\n<ol>\n<li>\u5143\u7d20\u8fd8\u662f\u4f7f\u7528\u7684<code>g<\/code>\u6574\u5408\uff0csvgstore\u4ee5\u524d\u4e5f\u662f\uff0c\u540e\u6765\u6539\u6210\u4e86<code>symbol<\/code>, \u8fd9\u91cc\u4e5f\u53ef\u80fd\u5728\u4e00\u6bb5\u65f6\u65e5\u540e\u4e5f\u4f1a\u4fee\u6539\uff0c\u4f46\u5e76\u4e0d\u786e\u5b9a\uff1b<\/li>\n<li>\u540d\u4e3a<code>sprites.html<\/code>\u7684demo\u9875\u9762\u7684SVG\u8fd8\u4f7f\u7528\u4e86<code>viewbox<\/code>\u505a\u9650\u5236\uff0c\u6211\u6d4b\u8bd5\u4e86\uff0c\u5220\u6389\u4f3c\u4e4e\u4e5f\u6ca1\u95ee\u9898\uff1b<\/li>\n<\/ol>\n<p><strong>\u8865\u5145\u4e8e2014\u5e7412\u670821\u65e5<\/strong><br \/>\n<strong>\u6ce8\u610f\u6ce8\u610f\uff1a<\/strong>SVG Sprite\u6280\u672f\u662f<strong>\u652f\u6301\u5916\u94feSVG\u6587\u4ef6<\/strong>\u7684\uff0c\u4f8b\u5982\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>&lt;svg viewBox=\"0 0 100 100\"> &lt;use xlink:href=\"defs.svg#icon-1\">&lt;\/use> &lt;\/svg><\/pre>\n<\/div>\n<p>\u6240\u4ee5\uff0c\u5f88\u591a\u4e0d\u559c\u6b22\u5185\u8054SVG\u7684\u5c0f\u4f19\u4f34\u5927\u53ef\u653e\u5fc3\u4f7f\u7528\u8be5\u6280\u672f\u3002\u4f46\u662f\uff0c\u7f8e\u4e2d\u4e0d\u8db3\u7684\u662f\uff0c\u76ee\u524d\uff0c\u6240\u6709\u7684IE\u6d4f\u89c8\u5668(\u5305\u62ecIE11)\u8fd8\u4e0d\u652f\u6301\u83b7\u5f97\u5916\u94feSVG\u6587\u4ef6\u67d0\u4e2a\u5143\u4ef6\u3002Chrome\/FireFox\/Safari\/Opera\u7b49\u6d4f\u89c8\u5668\u90fd\u662fOK\u7684\u3002<\/p>\n<p><strong>\u8865\u5145\u4e8e2015\u5e743\u670818\u65e5<\/strong><br \/>\nSVG Sprite\u6280\u672f\u662f\u652f\u6301\u76f4\u63a5Ajax\u8bf7\u6c42SVG\u6587\u4ef6\u5b57\u7b26\u4e32\u7684\u3002\u56e0\u6b64\uff0c\u5bf9\u4e8e\u4e0d\u652f\u6301\u5916\u94fe\u7684IE9+\u6d4f\u89c8\u5668\uff0c\u53ef\u4ee5\u76f4\u63a5\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>var ajax = new XMLHttpRequest();\r\najax.open(\"GET\", \"..\/201407\/mytest.svg\", true);\r\najax.onload = function(e) {\r\n    document.body.insertAdjacentHTML(\"afterBegin\", '&lt;div style=\"display:none;\">' + ajax.responseText + '&lt;\/div>');\r\n}\r\najax.send();<\/pre>\n<\/div>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a class=\"a_link\" href=\"http:\/\/www.zhangxinxu.com\/study\/201503\/svg-sprite-ajax.html\" target=\"_blank\">Ajax\u8bf7\u6c42SVG\u6587\u4ef6\u5b9e\u73b0Sprites\u6548\u679cDemo<\/a><\/p>\n<p>\u4f8b\u5982\uff0cIE9\u6d4f\u89c8\u5668\u4e0b\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201503\/2015-03-18_235131.png\" width=\"411\" height=\"216\" alt=\"IE9\u6d4f\u89c8\u5668\u4e0bSVG Ajax\u8bf7\u6c42\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<p>\u56e0\u6b64\uff0c\u5927\u5bb6\u5927\u53ef\u4e0d\u5fc5\u62c5\u5fc3SVG\u8d44\u6e90\u7ba1\u7406\u4e4b\u7c7b\u7684\u95ee\u9898\u3002IE9\u7b49\u6d4f\u89c8\u5668\uff0c\u4e00\u6b21Ajax\u6210\u529f\u540e\uff0c\u53ef\u4ee5\u76f4\u63a5\u672c\u5730\u5b58\u50a8\uff0c\u60f3\u60f3\u5c31\u5f88\u68d2\uff01<\/p>\n<p><strong>\u8865\u5145\u4e8e2016\u5e7410\u670827\u65e5<\/strong><br \/>\n\u90e8\u5206\u534e\u4e3aAndroid\u624b\u673a\uff0c\u8fd9\u79cd\u540e\u7f6e\u7684ajax\u8bf7\u6c42SVG\u5199\u5165\u65b9\u5f0f\u65e0\u6cd5\u5448\u73b0\u5c0f\u56fe\u6807\uff0c\u5982\u679c\u5728\u9875\u9762\u5934\u90e8\u4e00\u5f00\u59cb\u5c31\u6709SVG\u6587\u4ef6\u4ee3\u7801\u8d44\u6e90\uff0c\u5219\u6ca1\u6709\u6b64\u95ee\u9898\uff0c\u56fe\u6807\u4e0d\u4f1a\u663e\u793a\u4e0d\u51fa\u6765\u3002<\/p>\n<p>\u8981\u4fee\u590d\u6b64\u65b9\u6cd5\uff0c\u53ef\u4ee5\u628aSVG\u8d44\u6e90\u4f5c\u4e3a\u4e00\u4e2aJS\u8d44\u6e90\u8f7d\u5165\uff0c\u4f8b\u5982\uff0c\u547d\u540d\u4e00\u4e2a\u540d\u53eb<code>sprite.js<\/code>\uff0c\u91cc\u9762\u4ee3\u7801\u5927\u81f4\u5982\u4e0b\uff1a<\/p>\n<pre>var SVG = '&lt;svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\"&gt;&lt;symbol id=\"icon-arrow-l\" viewBox=\"0 0 8 16\"&gt;&lt;path d=\"M.146 7.646a.5.5 0 0 0 0 .708l7 7a.5.5 0 0 0 .708-.708l-7-7v.708l7-7a.5.5 0 0 0-.708-.708l-7 7z\"\/&gt;&lt;\/symbol&gt;&lt;symbol id=\"icon-arrow-r\" viewBox=\"0 0 7 12\"&gt;&lt;path d=\"M6.146 6.354v-.708l-5.5 5.5a.5.5 0 0 0 .708.708l5.5-5.5a.5.5 0 0 0 0-.708l-5.5-5.5a.5.5 0 1 0-.708.708l5.5 5.5z\"\/&gt;&lt;\/symbol&gt;&lt;symbol ....&lt;\/symbol&gt;&lt;\/svg&gt;';\r\ndocument.body.insertAdjacentHTML(\"afterBegin\", '<div hidden>' + SVG + '<\/div>');<\/pre>\n<p>\u7136\u540e\u5728\u9875\u9762<code>body<\/code>\u6807\u7b7e\u7684\u4e0b\u9762\uff0c\u76f4\u63a5\uff1a<\/p>\n<pre>&lt;script src=\"sprite.js\"&gt;&lt;\/script&gt;<\/pre>\n<p>\u7c7b\u4f3c\u4e0b\u56fe\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201610\/2016-10-27_150649.png\" width=\"338\" height=\"105\" alt=\"sprite.js\u653e\u7f6e\u5728body\u6807\u7b7e\u7684\u4e0b\u9762\" class=\"alignnone\" \/><\/p>\n<p><strong>\u8865\u5145\u4e8e2018\u5e7408\u670819\u65e5<\/strong><\/p>\n<p>\u505a\u4e86\u4e2aSVG\u5728\u7ebf\u538b\u7f29\u5408\u5e76\u5de5\u5177\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/sp\/svgo\/\" rel=\"noopener\" class=\"a_link\" target=\"_blank\">SVG\u5728\u7ebf\u538b\u7f29\u5408\u5e76\u5de5\u5177<\/a><\/p>\n<p>\u538b\u7f29\u5e95\u5c42\u57fa\u4e8eSVGO\uff0c\u4e0a\u4f20SVG\u6587\u4ef6\u4eec\uff0c\u5373\u53ef\u5b9e\u65f6\u5408\u5e76\u6210SVG sprites\uff0c\u53ef\u4ee5\u4e0b\u8f7d\u6216\u590d\u5236\u4f7f\u7528\u3002<\/p>\n<p><strong>\u8865\u5145\u4e8e2019-08-05<\/strong><\/p>\n<p>\u505a\u4e86\u4e2aSVG Sprites\u8fd8\u539f\u4e0e\u7ba1\u7406\u7684\u5728\u7ebf\u5de5\u5177\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/sp\/icon\/\" rel=\"noopener\" class=\"a_link\" target=\"_blank\">SVG  Sprites\u8fd8\u539f\u4e0e\u7ba1\u7406\u5728\u7ebf\u5de5\u5177<\/a><\/p>\n<p>\u6bcf\u4e2aSVG\u5c0f\u56fe\u6807\u53ef\u4ee5\u72ec\u7acb\u4e0b\u8f7d\uff0c\u4e5f\u53ef\u4ee5\u590d\u5236\u5185\u8054SVG\u4ee3\u7801\uff0c\u6216\u8005base64\u4ee3\u7801\u6216\u8005\u4f5c\u4e3aCSS\u80cc\u666f\u4f7f\u7528\u7684\u8f6c\u4e49SVG\u4ee3\u7801\u3002<\/p>\n<p>\u5185\u7f6e1500\u591a\u4e2a Font Awesome\u5c0f\u56fe\u6807\uff0c\u5bf9\u4e8e\u4e00\u4e9b\u8981\u6c42\u4e0d\u9ad8\u7684\u9879\u76ee\uff0c\u53ef\u4ee5\u76f4\u63a5\u590d\u5236\u8fd9\u4e9b\u5c0f\u56fe\u6807\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201908\/2019-08-05_001717.png\" width=\"500\" height=\"429\" alt=\"SVG Sprites\u8fd8\u539f\u5de5\u5177\u622a\u56fe\" class=\"alignnone size-medium\" \/><\/p>\n<p><strong>\u8865\u5145\u4e8e2019-11-04<\/strong><\/p>\n<p>\u5728IE9-IE11-Edge38\u7248\u672c\u6d4f\u89c8\u5668\u4e0b\uff0c\u70b9\u51fb<code>&lt;svg&gt;<\/code>\u5143\u7d20\u7684\u65f6\u5019\uff0cevent.target\u4e0d\u662fSVGUseElement\uff0c\u800c\u662fSVGElementInstance\u5143\u7d20\uff0c\u6b64\u65f6\uff0c\u4e00\u4e9bDOM API\u65b9\u6cd5\u4f7f\u7528\u4f1a\u62a5\u9519\uff0c\u4f8b\u5982<code>event.target.getAttribute()<\/code>\u65b9\u6cd5\uff0c\u56de\u62a5\u201c\u5bf9\u8c61\u4e0d\u652f\u6301\u6b64\u5c5e\u6027\u6216\u65b9\u6cd5\u201d\u7684\u9519\u8bef\u3002\u6b64\u65f6\uff0c\u53ef\u4ee5\u53c2\u7167\u4e0b\u9762\u7684\u505a\u6cd5\u52a0\u4e2apolyfill\u8865\u4e01\uff0c\u76f4\u63a5\u590d\u5236\u7c98\u8d34\u5c31\u53ef\u4ee5\u4e86\uff1a<\/p>\n<pre><span style=\"color:green;\">\/**\r\n * IE 11 - Edge 38 event.target\u662fSVGElementInstance\u5143\u7d20\u95ee\u9898\u4fee\u590d\r\n * @param  {[type]} [description]\r\n * @return {[type]} [description]\r\n *\/<\/span>\r\nif (window.SVGElementInstance) {\r\n    SVGElementInstance.prototype.getAttribute = function (attributeName) {\r\n        if (this.correspondingUseElement) {\r\n            return this.correspondingUseElement.getAttribute(attributeName);\r\n        }\r\n    };\r\n}<\/pre>\n<h3>\u4e03\u3001\u552f\u4e00\u7684\u5236\u7ea6\u2014\u2014\u517c\u5bb9\u6027<\/h3>\n<p>SVG\u56fe\u6807\u5fc5\u5b9a\u662f\u672a\u6765\u7684\u8d8b\u52bf\u3002\u4e3a\u4f55\u73b0\u5728\u56fd\u5185\u4f9d\u7136\u4e0d\u6e29\u4e0d\u706b\uff0c\u4e0d\u5bf9\uff0c\u5e94\u8be5\u662f\u8fd8\u6ca1\u6709\u5f00\u59cb\u6709\u6e29\u5ea6\u3002\u6211\u89c9\u5f97\u9664\u4e86\u6280\u672f\u5b66\u4e60\u6ede\u540e\u6027\uff0c\u6d4f\u89c8\u5668\u517c\u5bb9\u6027\u662f\u6700\u5173\u952e\u7684\u5236\u7ea6\uff0c\u6bd5\u7adfIE8\u76ee\u524d\u4f9d\u7136\u662f\u5927\u5934(33.23%, \u521a\u5728\u767e\u5ea6\u6d41\u91cf\u7814\u7a76\u9662\u770b\u5230\u7684\u6570\u636e)\u3002<\/p>\n<p>\u5982\u4f55\u7834\uff1f\u6309\u7167\u6211\u7684\u5fc3\u60c5\uff0c\u9e1f\u5b83\u4e2a\u6bdb\u7ebf\uff0c\u6211\u5c31\u624b\u673a\u4e0a\u7528\u7528\uff0c\u4e0d\u4e5f\u633a\u597d\u3002\u9759\u4e0b\u6765\u60f3\u60f3\uff0c\u4e0d\u80fd\u610f\u6c14\u7528\u4e8b\uff0c\u63d0\u4e00\u4e0bIE7\/IE8\u6d4f\u89c8\u5668\u7684\u5904\u7406\u65b9\u6cd5\u5427~<\/p>\n<p>\u6709\u4e9b\u6807\u7b7e\uff0c\u6d4f\u89c8\u5668\u8bc6\u522b\uff0c\u4f1a\u5ffd\u7565\u91cc\u9762\u4e00\u4e9b\u4e1c\u897f\u3002\u4f8b\u5982SVG\u7684<code>desc<\/code>\u5143\u7d20\uff0c\u91cc\u9762\u7684\u5185\u5bb9\u4e00\u5411\u4e0d\u663e\u793a\u7684\u3002\u4e8e\u662f\uff0c\u5bf9\u4e8eIE7\/IE8, \u6211\u4eec\u53ef\u4ee5\u628a\u5bf9\u5e94\u56fe\u6807\u7684<code>png<\/code>\u56fe\u7247\u653e\u5728\u5176\u4e2d\uff0c\u7136\u540eIE9+\u7b49\u652f\u6301SVG\u7684\u6d4f\u89c8\u5668\u5c31\u4f1a\u5ffd\u7565\u4e4b\uff0c\u800cIE7\/IE8\u8fd9\u4e9b\u4e0d\u8bc6\u6cf0\u5c71\u7684\u5143\u7d20\u5c31\u4f1a\u663e\u793a\u56fe\u7247\u3002\u62ff\u793c\u7269\u8fd9\u4e2aSVG\u4e3e\u4f8b\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>&lt;svg class=\"webicon\">\r\n    &lt;desc>&lt;img src=\"iconfont-baobei.png\" width=\"16\" height=\"16\">&lt;\/desc>\r\n    &lt;use xlink:href=\"#liwu\"\/>\r\n&lt;\/svg>\u5151\u6362\u793c\u7269<\/pre>\n<\/div>\n<p>\u4e8e\u662f\uff0c\u5728IE8\u4e0b\uff0c\u5c31\u4f1a\u662f\u8fd9\u6837\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_172222.png\" width=\"228\" height=\"167\" alt=\"IE8\u6d4f\u89c8\u5668\u4e0b\u6548\u679c\" class=\"alignnone\" \/><\/p>\n<p>\u5176\u4ed6\u9760\u8c31\u6d4f\u89c8\u5668\u4f9d\u7136\u662f\u8fd9\u6837\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" width=\"327\" height=\"208\" alt=\"SVG\u4f7f\u7528\u7684\u56fe\u6807\u6548\u679c\" class=\"alignnone\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/2014-07-10_142916.png\"><\/p>\n<p>\u4e8e\u662f\uff0c\u5b8c\u7f8e\u517c\u5bb9\u4e86\u3002\u53ea\u662f\u6d3b\u8131\u8131\u591a\u4e86\u4e2a\u6807\u7b7e\uff0c\u7565\u8d25\u5174\u3002\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u9488\u5bf9IE7\/IE8\u4f7f\u7528CSS Sprite\u6280\u672f\uff0c\u539f\u7406\u7c7b\u4f3c\uff0c\u53ea\u662f<code>img<\/code>\u6807\u7b7e\u6362\u6210\u5176\u4ed6<code>i<\/code>\u4e4b\u7c7b\u6807\u7b7e\u663e\u793a\u80cc\u666f\u56fe\uff0c\u81f3\u5c11HTML\u8fd9\u5757\u4f1a\u5e72\u51c0\u5f88\u591a\u3002<\/p>\n<h3>\u516b\u3001\u7ed3\u675f\u8bed<\/h3>\n<p>\u4eca\u5e744\u6708\u4efd\u7684\u65f6\u5019\u521a\u4ecb\u7ecd\u8fc7\u201c<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=4113\">CSS3\u56fe\u6807\u56fe\u5f62\u751f\u6210\u6280\u672f<\/a>\u201d\uff0c\u5982\u679c\u8bf4\u201c<code>font-face<\/code>\u56fe\u6807\u751f\u6210\u6280\u672f\u201d\u662f\u70ed\u95e8\u7684\u8bdd\uff0c\u90a3\u201cCSS3\u56fe\u6807\u751f\u6210\u6280\u672f\u201d\u5219\u5c5e\u4e8e\u504f\u95e8\uff0c\u53d7\u8bbe\u8ba1\u5236\u7ea6\u5f88\u5927\uff0c\u800c\u672c\u6587\u4ecb\u7ecd\u7684\u201cSVG Sprite\u56fe\u6807\u751f\u6210\u201d\u5219\u4ee3\u8868\u4e86\u672a\u6765\u3002<\/p>\n<p><code>font-face<\/code>\u5728\u90e8\u5206win\u7cfb\u7edf\u4e0b\uff0c\u5b57\u4f53\u8f83\u5c0f\u7684\u65f6\u5019\uff0c\u952f\u9f7f\u95ee\u9898\u5f88\u8ba8\u538c\uff0c\u82db\u523b\u7684\u8bbe\u8ba1\u5e08\u65e0\u6cd5\u5fcd\u53d7\uff0c\u751a\u81f3\u51fa\u73b0\u4e86\u54cd\u5e94\u5f0f<code>font-face<\/code>\u8fd9\u6837\u7684\u540d\u5802\uff0c\u4f46\u662f\uff0c\u636e\u6211\u89c2\u5bdf\uff0c\u7eaf\u6b63\u7684SVG\u56fe\u6807\u662f\u6ca1\u6709\u8fd9\u4e2a\u95ee\u9898\u7684\uff0c\u800c\u4e14\uff0cSVG\u56fe\u6807\u5177\u5907<code>font-face<\/code>\u51e0\u4e4e\u6240\u6709\u7684\u4f18\u70b9\uff0c\u5c3a\u5bf8CSS\u53ef\u968f\u610f\u5b9a\u5236\uff0c\u989c\u8272CSS\u53ef\u968f\u610f\u5b9a\u5236\uff1b\u4e14\u6ca1\u6709<code>font-face<\/code>\u5f02\u6b65\u52a0\u8f7d\u5ef6\u65f6\u6e32\u67d3\u95ee\u9898\uff1b\u540c\u65f6\u6ca1\u6709\u67d0\u4e9b\u6d4f\u89c8\u5668\u4e0b<code>font-face<\/code>\u8de8\u57df\u95ee\u9898\uff1b\u66f4\u5173\u952e\u7684\u662f\uff0cSVG\u56fe\u6807\u652f\u6301\u6e10\u53d8\uff0c\u751a\u81f3\u5f69\u8272\u56fe\u6807\u7684\u3002\u800c<code>font-face<\/code>\u5b9e\u73b0\u5f69\u8272\u56fe\u6807\uff0c\u8981\u4e00\u4e2a\u4e00\u4e2a\u62fc\u8d77\u6765\uff0c\u4f60\u4ee5\u4e3a\u8d34\u9a6c\u8d5b\u514b\u554a\uff01\u800c\u4e14\uff0cSVG\u4e2d\u6bcf\u4e2a<code>path<\/code>\u5143\u7d20\u7b49\u53ef\u4ee5\u72ec\u7acb\u63a7\u5236\uff0c\u5e05\u6c14\u7684\u56fe\u6807\u53d8\u6362\u52a8\u753b\u7b49\u7684\u5c31\u662f\u4f60\u6765\u5b9e\u73b0(<span class=\"g9\">add on 2014\/7\/18<\/span> <a href=\"http:\/\/tympanus.net\/Development\/AnimatedSVGIcons\/\">\u8fd9\u4e2a\u9875\u9762<\/a>N\u591aSVG\u56fe\u6807\u52a8\u753b)\uff01<\/p>\n<p>\u56e0\u6b64\uff0c\u5404\u65b9\u9762\u770b\uff0cSVG\u5b8c\u80dc<code>font-face<\/code>, <\/p>\n<p>\u76ee\u524d\u552f\u4e00\u7684\u95ee\u9898\u5c31\u662f\u517c\u5bb9\u6210\u672c\uff08\u5f53\u7136\uff0c\u4e1a\u754c\u8fd8\u662f\u6709\u5f88\u591a\u6210\u719f\u7684\u4f18\u96c5\u964d\u7ea7\u6280\u672f\uff0c\u53ef\u53c2\u89c1\u6211\u4e4b\u524d\u7684\u6587\u7ae0\u201c<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=3678\">\u4e00\u4e9bSVG\u5411\u4e0b\u517c\u5bb9\u4f18\u96c5\u964d\u7ea7\u6280\u672f<\/a>\u201d\uff09\u3002\u4f46\u662f\uff0c\u968f\u7740\u6d4f\u89c8\u5668\u7684\u53d1\u5c55\uff0cSVG\u4e00\u5b9a\u4f1a\u8fce\u6765\u81ea\u5df1Web\u65b0\u821e\u53f0\uff01<\/p>\n<p>\u611f\u8c22\u9605\u8bfb\uff0c\u6b22\u8fce\u4ea4\u6d41\uff0c\u8e0a\u8dc3\u7ea0\u9519\uff0c\u591a\u591a\u8d5e\u52a9\uff01<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/13.gif\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u4f1a\u7ecf\u5e38\u66f4\u65b0\u77e5\u8bc6\u70b9\u4ee5\u53ca\u4fee\u6b63\u4e00\u4e9b\u9519\u8bef\uff0c\u56e0\u6b64\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u539f\u51fa\u5904\uff0c\u65b9\u4fbf\u6eaf\u6e90\uff0c\u907f\u514d\u9648\u65e7\u9519\u8bef\u77e5\u8bc6\u7684\u8bef\u5bfc\uff0c\u540c\u65f6\u6709\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=4264\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=4264<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=4264\" title=\"\u70b9\u51fb\u67e5\u770b\u672c\u6587\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201407\/svg-sprite-cover.jpg\" class=\"imgpad mb10\" width=\"550\" height=\"170\" alt=\"\u672a\u6765\u5fc5\u70ed\uff1aSVG Sprite\u6280\u672f\u4ecb\u7ecd\"><\/a><br \/>\n\u672c\u6587\u662f\u672c\u6708\u6587\u7ae0\u7684\u538b\u8f74\u7bc7\uff0c\u4ecb\u7ecdSVG Sprite\u6280\u672f\u7684\u3002\u5185\u5bb9\u4e30\u5bcc\u5927\u800c\u5168\uff0c\u9762\u5411\u5404\u4e2a\u4eba\u7fa4\uff0c\u65e0\u8bba\u4f60\u662f\u5f00\u53d1\u8fd8\u662f\u8bbe\u8ba1\uff0c\u8fd8\u662f\u7eaf\u6b63\u7684\u524d\u7aef\uff0c\u90fd\u53ef\u4ee5\u5728web\u4e2d\u4f7f\u7528SVG Sprite\u6280\u672f\uff0c\u6bd4CSS Sprite\u6280\u672f\u5e94\u7528\u8fd8\u8981\u7b80\u5355\u3002\u53ef\u8c13\u8001\u5c11\u7686\u5b9c\uff0c\u51fa\u95e8\u65c5\u884c\uff0c\u5fc5\u5907\u4f73\u80b4\u3002\u597d\u4e86\uff0c\u5c31\u4e0d\u8c03\u76ae\u4e86\uff0c\u622a\u56fe\u6bd4\u8f83\u591a\uff0c\u5185\u5bb9\u4e5f\u4e0d\u5c11\uff0c\u603b\u4e4b\uff0c\u5e0c\u671b\u672c\u6587\u7684\u5185\u5bb9\u80fd\u591f\u5bf9\u60a8\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[895],"tags":[359,932,933,918,642,929,930,931,866,722],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/4264"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=4264"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/4264\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=4264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=4264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=4264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}