{"id":3678,"date":"2013-09-22T10:19:54","date_gmt":"2013-09-22T02:19:54","guid":{"rendered":"http:\/\/www.zhangxinxu.com\/wordpress\/?p=3678"},"modified":"2018-01-02T03:20:47","modified_gmt":"2018-01-01T19:20:47","slug":"svg-fallbacks","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2013\/09\/svg-fallbacks\/","title":{"rendered":"\u4e00\u4e9bSVG\u5411\u4e0b\u517c\u5bb9\u4f18\u96c5\u964d\u7ea7\u6280\u672f"},"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=3678\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=3678<\/a><\/p>\n<h3>\u4e00\u3001SVG\u524d\u8a00<\/h3>\n<p>\u518d\u4e00\u6b21\u62ff\u53ef\u7f29\u653e\u77e2\u91cf\u56fe\u5f62SVG(Scalable Vector Graphics)\u8bf4\u4e8b\uff0c\u5bf9SVG\u6709\u6240\u5173\u6ce8\u7684\u540c\u884c\u5e94\u8be5\u90fd\u77e5\u9053\uff0cIE8-\u4ee5\u53caAndroid 2.3\u9ed8\u8ba4\u6d4f\u89c8\u5668\u662f\u4e0d\u652f\u6301SVG\u7684\uff0c\u5b9e\u9645\u9879\u76ee\uff0c\u8fd9\u4e9b\u6d4f\u89c8\u5668\uff0c\u81f3\u5c11IE8\u6d4f\u89c8\u5668\u8fd8\u6ca1\u6709\u5230\u4e0d\u7ba1\u4e0d\u95ee\u7684\u65f6\u5019\uff0c\u56e0\u6b64\uff0c\u5728\u4f7f\u7528\u89c6\u7f51\u819c\u663e\u793a\u53cb\u597d\u7684SVG\u540c\u65f6\uff0c\u6211\u4eec\u8fd8\u8981\u505a\u4e00\u70b9\u4f18\u96c5\u964d\u7ea7\uff0c\u4f7fIE8\u7b49\u8003\u53e4\u4ef7\u503c\u6d4f\u89c8\u5668\u4e5f\u80fd\u624b\u67d3\u4f59\u9999\u3002<\/p>\n<p>\u672c\u6587\u5185\u5bb9\u53c2\u8003\u81eaCSS-tricks <a href=\"http:\/\/css-tricks.com\/svg-fallbacks\/\">SVG fallbacks<\/a>\u4e00\u6587\uff0c\u8be5\u6587\u7ae0\u5728\u4ecb\u7ecd\u4e00\u79cd\u65b0\u7684SVG\u964d\u7ea7\u6280\u672f\u7684\u540c\u65f6\uff0c\u628a\u4ee5\u524d<a href=\"http:\/\/css-tricks.com\/using-svg\/\">Using SVG<\/a>\u4e2d\u63d0\u5230\u7684\u6280\u672f\u53c8\u603b\u7ed3\u4e86\u4e00\u904d\u3002\u5927\u96c6\u5408\u4ec0\u4e48\u7684\u6211\u505a\u559c\u6b22\u4e86\uff0c\u4ee5\u540e\u4e0d\u8981\u627e\u6765\u627e\u53bb\uff0c\u56e0\u6b64\uff0c\u8fd9\u91cc\uff0c\u6211\u6309\u7167\u4e2a\u4eba\u7684\u7406\u89e3\uff0c\u914d\u5408\u81ea\u5df1\u7684\u4e00\u4e9b\u5b9e\u9645\u6d4b\u8bd5\uff0c\u5206\u4eab\u4e0b\u3002<\/p>\n<p>\u672c\u6587\u5185\u5bb9\u5f53\u4e0b\u53ef\u80fd\u4e0d\u6e29\u4e0d\u706b\uff0c\u4f46\u660e\u5e74\u7684\u4eca\u5929\uff0c\u4f30\u8ba1\u5c31\u4e0d\u4e00\u6837\u4e86\uff0c\u8bb0\u4f4f\u8fd9\u91cc\uff0c\u968f\u65f6\u5230\u8bbf\u3002<\/p>\n<h3>\u4e8c\u3001svg image\u6807\u7b7e\u964d\u7ea7\u6280\u672f<\/h3>\n<p>\u8fd9\u662f\u4e00\u4e2a\u540d\u53ebAlexey Ten\u9996\u5148\u63d0\u51fa\u6765\u7684\uff0c\u7c7b\u4f3c\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>&lt;svg width=\"96\" height=\"96\">\n  &lt;image xlink:href=\"svg.svg\" src=\"svg.png\" width=\"96\" height=\"96\" \/>\n&lt;\/svg><\/pre>\n<\/div>\n<p>\u82e5\u5bf9\u4e0a\u9762\u4ee3\u7801\u6548\u679c\u611f\u5174\u8da3\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a class=\"a_link\" href=\"http:\/\/www.zhangxinxu.com\/study\/201309\/svg-fallbacks-image.html\" target=\"_blank\">svg image\u6807\u7b7e\u964d\u7ea7\u6280\u672fdemo<\/a><\/p>\n<p>\u73b0\u4ee3\u6d4f\u89c8\u5668\u4e0b\uff0c\u4f8b\u5982Chrome\u4e0b\uff0c\u5c31\u662fSVG\u5f62\u5f0f\u663e\u793a\uff0c\u5982\u4e0b\u622a\u56fe\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201309\/2013-09-17_202130.png\" width=\"319\" height=\"217\" alt=\"Chrome\u6d4f\u89c8\u5668\u4e0bSVG\u6548\u679c\" class=\"alignnone\" \/><\/p>\n<p>IE7\u4e0b\u5219\u662fpng\u56fe\u7247\u663e\u793a\u7684\u6548\u679c\uff0c\u5982\u4e0b\u622a\u56fe\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201309\/2013-09-17_202208.png\" width=\"333\" height=\"212\" alt=\"IE7\u6d4f\u89c8\u5668\u4e0bpng\u56fe\u7247\u663e\u793a\u622a\u56fe\" class=\"alignnone\" \/><\/p>\n<p>\u4e0a\u9762\u8fd9\u4e2a\u6280\u672f\u662f\u975e\u5e38\u5de7\u5999\u7684\uff0c\u5176\u521b\u610f\u501f\u9274\u4e86<a href=\"http:\/\/jakearchibald.com\/2013\/having-fun-with-image\/\">Jake Archibald\u7684\u4e00\u4e2a\u7814\u7a76<\/a>\uff0c\u5373\u6240\u6709\u6d4f\u89c8\u5668\uff0c\u5305\u62ecIE\uff0c\u4f1a\u628a<code>image<\/code>\u6807\u7b7e\u6e32\u67d3\u6210<code>img<\/code>\u6807\u7b7e\uff0c\u800cSVG\u4e2d\u7684<code>image<\/code>\u4f5c\u7528\u662f\uff1a<\/p>\n<blockquote><p>Provides a way to display a graphics image on the screen.<\/p><\/blockquote>\n<p>\u4e5f\u5c31\u662f\u63d0\u4f9b\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u4e00\u4e2a\u56fe\u5f62\u56fe\u50cf\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u4e8e\u662f\uff0c\u5c31\u6709\uff0c\u5982\u679c\u6d4f\u89c8\u5668\u652f\u6301SVG\uff0c\u5219SVG\u663e\u793a\uff1b\u5bf9\u4e8e\u4e0d\u652f\u6301\u7684\u6d4f\u89c8\u5668\uff0c\u4f8b\u5982IE8\u6d4f\u89c8\u5668\uff0c\u4f1a\u5ffd\u7565<code>svg<\/code>\u6807\u7b7e\u7684\u5b58\u5728\uff0c\u76f4\u63a5\u6e32\u67d3<code>image<\/code>\uff0c\u5728\u5176\u770b\u6765\uff0c\u8fd9\u5c31\u662f\u4e2a<code>img<\/code>\u6807\u7b7e\uff0c\u4e8e\u662f\uff0c\u56fe\u50cf\u5c31\u4ee5<code>svg.png<\/code>\u7684\u5f62\u5f0f\u663e\u793a\u4e86\u3002<\/p>\n<p><strong>\u7565\u5fae\u7684\u4e0d\u723d<\/strong><br \/>\n\u5728iOS 3 and 4\u8bbe\u5907\u4e0a\uff0c<code>image<\/code>\u964d\u7ea7\u6280\u672f\u4f7f\u7528\u7684\u7ed3\u679c\u662f\u2014\u2014\u56fe\u7247\u663e\u793a\u3002\u4e8b\u5b9e\u4e0a\uff0c\u8fd9\u4e24\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u7684\u539f\u751f\u6d4f\u89c8\u5668\u662f\u652f\u6301SVG\u7684\uff0c\u6bd4\u65b9\u8bf4\u4ee5<code>&lt;img src=\"*.svg\"&gt;<\/code>\u5f62\u5f0f\uff0c\u6216\u8005CSS\u7684<code>background-image<\/code>\uff1b\u4f46\u662f\u5176\u552f\u72ec\u4e0d\u652f\u6301<code>inline<\/code> SVG, \u5c31\u662fSVG\u6807\u7b7e\u5f62\u5f0f\u5d4c\u5728HTML\u4ee3\u7801\u4e2d\u7684\u4f7f\u7528\u65b9\u6cd5\u662f\u4e0d\u652f\u6301\u7684\u3002\u4e8e\u662f\uff0c\u5bfc\u81f4\u7684\u7ed3\u679c\u662f\uff0c\u660e\u660e\u53ef\u4ee5SVG\u5f62\u5f0f\u663e\u793a\u7684\uff0c\u73b0\u5728\u8fd9\u79cd\u7528\u6cd5\u5c31\u53ea\u80fd<code>png<\/code>\u56fe\u7247\u663e\u793a\u4e86\uff0c\u7565\u4e0d\u723d\uff01<\/p>\n<p>\u7136\uff0ciOS 3 and 4\u8bbe\u5907\u5df2\u662f\u5f3a\u5f29\u4e4b\u672b\uff08\u73b0\u5728\u5df2\u7ecf<code>7<\/code>\u4e86\uff09\uff0c\u9762\u5bf9\u73b0\u5b9e\uff0c\u4e2a\u4eba\u89c9\u5f97\u73b0\u5728\u5df2\u7ecf\u6ca1\u5fc5\u8981\u5927\u60ca\u5c0f\u602a\u4e86\u3002\u56e0\u6b64\uff0c\u8fd9\u4e2a\u6280\u672f\uff0c\u4e2a\u4eba\u8fd8\u662f\u6bd4\u8f83\u63a8\u8350\u7684\u3002<\/p>\n<p><strong>\u8d44\u6e90\u4e0b\u8f7d\u7684\u7814\u7a76<\/strong><br \/>\n\u6839\u636e\u524d\u8f88\u7684\u8bf4\u6cd5\u4ee5\u53ca\u81ea\u5df1\u7684\u9a8c\u8bc1\uff0cIE8-\u6d4f\u89c8\u5668\u4ee5\u53caAndroid 2.3\u9ed8\u8ba4\u6d4f\u89c8\u5668\u4e0b\uff0c\u53ea\u4f1a\u4e0b\u8f7dpng\u56fe\u7247\uff0c\u800cChrome\u8fd9\u4e9b\u5662\u5566\u7684\u6d4f\u89c8\u5668\uff0c\u53ea\u4f1a\u4e0b\u8f7dSVG\u683c\u5f0f\u56fe\u5f62\u3002\u5982\u4e0b\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201309\/2013-09-18_152001.png\" width=\"565\" height=\"472\" alt=\"Chrome\u6d4f\u89c8\u5668\u7684\u4e0b\u8f7d\u8bf7\u6c42 \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" class=\"alignnone\" \/><\/p>\n<p>\u4f46\u662f\uff0c\u5728IE9~IE11\u6d4f\u89c8\u5668\u4e0b\uff0c\u60c5\u51b5\u5c31\u53d8\u5f97\u6709\u4e9b\u7279\u6b8a\u4e86\u3002<\/p>\n<p>\u56e0\u4e3a\u81ea\u5df1\u6ca1\u5fcd\u4f4f\u5347\u7ea7\u5230\u4e86IE11\uff0c\u56e0\u6b64\uff0c\u6ca1\u6709IE10\u7248\u672c\u4e0b\u7684\u52a0\u8f7d\u4eb2\u6d4b\u622a\u56fe\uff0c\u5148\u7528\u53c2\u8003\u6587\u7ae0\u4e2d\u7684\u56fe\u7247\u793a\u610f\u4e0b\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201309\/ie9-timeline.png\" width=\"560\" height=\"159\" alt=\"IE10\u6d4f\u89c8\u5668\u4e0bIE9\u52a0\u8f7d\" class=\"alignnone\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201309\/ie10-timeline.png\" width=\"560\" height=\"183\" alt=\"IE10\u6d4f\u89c8\u5668\u7684\u52a0\u8f7d\" class=\"alignnone\" \/><\/p>\n<p>\u4ece\u4e0a\u9762\u4e24\u4e2a\u6d4b\u8bd5\u622a\u56fe\u53ef\u4ee5\u770b\u51fa\uff0c\u5728IE10\u6d4f\u89c8\u5668\u4e0b\uff0c\u867d\u7136\u5176\u6807\u51c6IE10\u4ee5\u53caIE9\u90fd\u652f\u6301SVG\uff0c\u4f46\u662f\uff0c\u90fd\u53d1\u8d77\u4e86png\u56fe\u7247\u7684\u8bf7\u6c42\u3002\u4e0d\u8fc7\uff0c\u5f88\u6709\u610f\u601d\u7684\u662f\uff0c\u8be5\u8bf7\u6c42\u90fd\u88ababort\u4e86\uff0c\u88ab\u963b\u6b62\u4e86\uff0c\u8fd4\u56de\u4f53\u7684\u6570\u636e\u5927\u5c0f\u51e0\u4e4e\u6216\u8005\u5c31\u662f<code>0b<\/code>\uff0c\u4e5f\u5c31\u662f\u6ca1\u6709\u4efb\u4f55\u6570\u636e\u8fd4\u56de\u3002\u6d41\u91cf\u4f3c\u4e4e\u662f\u7701\u6389\u4e86\uff0c\u4f46\u662f\uff0c\u8bf7\u6c42\u7684\u65f6\u95f4\u4f9d\u65e7\u5b58\u5728\uff0c\u5982\u7b2c\u4e00\u5f20\u622a\u56fe\u6240\u793a\u7684<code>140ms<\/code>. \u6839\u636e\u67d0\u4e9b\u66f4\u51c6\u786e\u7684\u6d4b\u8bd5\uff0c\u8fd9\u4e2a\u5c0f\u5c0f\u8bf7\u6c42\uff0c\u867d\u7136\u53d1\u9001\u548c\u63a5\u53d7\u7684\u6570\u636e\u4e0d\u8fc7700\u591a\u5b57\u8282\uff0c\u4f46\u662f\uff0c\u6240\u8017\u8d39\u7684\u65f6\u95f4\u6709\u6570\u767e\u6beb\u79d2\u4e4b\u591a\u3002\u5982\u679c\u9875\u9762\u5934\u90e8\u6709\u963b\u585e\u811a\u672c\uff0c\u95ee\u9898\u5c31\u6bd4\u8f83\u4e25\u91cd\u4e86\u3002<\/p>\n<p>\u4e5f\u53ef\u80fd\u6b63\u662f\u7531\u4e8e\u8fd9\u79cd\u7565\u663e\u5947\u8469\u7684\u7279\u6027\uff0c\u5728IE11\u6d4f\u89c8\u5668\u4e2d\uff0c\u60c5\u51b5\u53c8\u6709\u5927\u7684\u6539\u53d8\uff0c\u4e0b\u9762\u662f\u6211\u5728win7 IE11\u4e0b\u7684\u6d4b\u8bd5\u622a\u56fe\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201309\/2013-09-18_143100.png\" width=\"593\" height=\"349\" alt=\"IE11\u7684\u663e\u793a\" class=\"alignnone\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201309\/2013-09-18_145311.png\" width=\"634\" height=\"283\" alt=\"IE11\u6d4f\u89c8\u5668\u4e0bIE9\u6a21\u5f0f\u4e0bSVG\u8bf7\u6c42\" class=\"alignnone\" \/><\/p>\n<p>\u53ef\u4ee5\u770b\u5230\uff0cIE11\u6d4f\u89c8\u5668\u4e0b\uff0c\u867d\u7136\u663e\u793a\u7684\u53ea\u6709SVG\uff0c\u4f46\u662f\uff0cpng\u683c\u5f0f\u56fe\u7247\u5982\u82e5\u65e0\u4eba\u5730\u52a0\u8f7d\u8fdb\u6765\u4e86\uff0c\u4ee5\u4e00\u79cd\u666e\u901a\u56fe\u7247\u7684\u59ff\u6001\u88ab\u52a0\u8f7d\u8fdb\u6765\u4e86\u3002\u4e14\u987a\u5e26\u5f71\u54cd\u4e86\u5176\u5c0f\u5f1f\u6a21\u5f0f\uff0c\u5982IE9\u6a21\u5f0f\u4e5f\u662f\u8fd9\u526f\u62fd\u6a21\u6837\u3002<\/p>\n<p><strong>\u6d4b\u8bd5\u7ed3\u679c\u5927\u6c47\u603b<\/strong><\/p>\n<style>.problem td, .problem th { background-color: pink; }.good td, .good th { background-color: lightgreen; }<\/style>\n<table class=\"params_table\" width=\"100%\" cellpadding=\"0\" cellspacing=\"1\">\n<tr>\n<th>&lt;svg>&lt;image><\/th>\n<td>\n      <svg width=\"96\" height=\"96\"><image xlink:href=\"\/study\/image\/svg\/svg.svg\" src=\"\/study\/image\/svg\/svg.png\" width=\"96\" height=\"96\" \/><\/svg>\n    <\/td>\n<\/tr>\n<tr>\n<th>&lt;img src=svg.svg><\/th>\n<td>\n      <img decoding=\"async\" src=\"\/study\/image\/svg\/svg.svg\" \/>\n    <\/td>\n<\/tr>\n<\/table>\n<table class=\"params_table\" width=\"100%\" cellpadding=\"0\" cellspacing=\"1\">\n<tr>\n<th>Browser<\/th>\n<th>&lt;image> \u6280\u672f<\/th>\n<th>\u6b63\u5e38 &lt;img><\/th>\n<th>\u4e0b\u8f7d<\/th>\n<\/tr>\n<tr class=\"good\">\n<th>Chrome 28<\/th>\n<td>SVG<\/td>\n<td>SVG<\/td>\n<td>\u4ec5SVG<\/td>\n<\/tr>\n<tr>\n<th>IE 8<\/th>\n<td>PNG<\/td>\n<td>&#8212;<\/td>\n<td>\u4ec5PNG (<a href=\"http:\/\/waterpigs.co.uk\/notes\/4RdDTh\/\">via<\/a>)<\/td>\n<\/tr>\n<tr class=\"problem\">\n<th>IE 9<\/th>\n<td>SVG<\/td>\n<td>SVG<\/td>\n<td>\u963b\u65ad<code>.png<\/code>, \u4f46\u4ecd<a href=\"http:\/\/cl.ly\/Qt1g\">\u8017\u8d39\u65f6\u95f4<\/a><\/td>\n<\/tr>\n<tr class=\"problem\">\n<th>IE 10<\/th>\n<td>SVG<\/td>\n<td>SVG<\/td>\n<td>\u4e5f\u662f\u58f0\u79f0<a href=\"http:\/\/cl.ly\/QsAQ\">\u963b\u65ad<\/a> &#8211; \u4f46\u662f\u770b\u4e0a\u53bb<a href=\"http:\/\/cl.ly\/QsoS\">\u4e24\u8005\u90fd\u4e0b\u8f7d<\/a><\/td>\n<\/tr>\n<tr class=\"problem\">\n<th>IE 11<\/th>\n<td>SVG<\/td>\n<td>SVG<\/td>\n<td>\u6216<a href=\"https:\/\/twitter.com\/stopsatgreen\/status\/369377796654526464\">\u963b\u65ad<\/a>\u6216<a href=\"https:\/\/twitter.com\/andydavies\/status\/369404411191115776\">\u4e0d\u963b\u65ad<\/a> (\u90fd\u4e0d\u9760\u8c31)<\/td>\n<\/tr>\n<tr class=\"problem\">\n<th>iPhone 3GS (iOS 3)<\/th>\n<td>PNG<\/td>\n<td>SVG<\/td>\n<td>\u9700\u8981\u6d4b\u8bd5<\/td>\n<\/tr>\n<tr class=\"problem\">\n<th>iPhone 4 (iOS 4)<\/th>\n<td>PNG<\/td>\n<td>SVG<\/td>\n<td>\u4ec5PNG (<a href=\"http:\/\/waterpigs.co.uk\/notes\/4RdDTh\/\">\u6765\u81ea<\/a>)<\/td>\n<\/tr>\n<tr>\n<th>iPhone 4S (iOS 5)<\/th>\n<td>SVG<\/td>\n<td>SVG<\/td>\n<td>\u9700\u8981\u6d4b\u8bd5<\/td>\n<\/tr>\n<tr class=\"good\">\n<th>iPhone 5 (iOS 6)<\/th>\n<td>SVG<\/td>\n<td>SVG<\/td>\n<td>\u4ec5SVG<\/td>\n<\/tr>\n<tr class=\"good\">\n<th>Android 2.3<\/th>\n<td>PNG<\/td>\n<td>&#8212;<\/td>\n<td>\u4ec5PNG (<a href=\"https:\/\/twitter.com\/stopsatgreen\/status\/369425371260649472\">\u6765\u81ea<\/a>)<\/td>\n<\/tr>\n<tr class=\"good\">\n<th>Android 4<\/th>\n<td>SVG<\/td>\n<td>SVG<\/td>\n<td>\u4ec5SVG (<a href=\"https:\/\/twitter.com\/stopsatgreen\/status\/369386590335815680\">\u6765\u81ea<\/a>)<\/td>\n<\/tr>\n<tr class=\"good\">\n<th>Firefox 22<\/th>\n<td>SVG<\/td>\n<td>SVG<\/td>\n<td>\u4ec5SVG<\/td>\n<\/tr>\n<\/table>\n<h3>\u4e09\u3001\u5176\u4ed6\u65b9\u5f0f\u4e0b\u7684\u964d\u7ea7\u6280\u672f<\/h3>\n<p><strong>1. \u5982\u679c\u4f60\u4f7f\u7528SVG\u4f5c\u4e3a<code>background\uff0dimage<\/code><\/strong><br \/>\nModernizr\u6709\u4e00\u4e2a<a href=\"http:\/\/modernizr.com\/docs\/#features-misc\">SVG\u6d4b\u8bd5<\/a>\uff0c\u53ef\u4ee5\u5224\u5b9a\u8bbe\u5907\u662f\u5426\u652f\u6301SVG\uff0c\u4e8e\u662f\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u901a\u8fc7\u5728HTML\u5143\u7d20\u4e0a\u6dfb\u52a0\u7279\u5b9a\u7684\u7c7b\u540d(eg. <code>no-svg<\/code>)\uff0c\u505a\u4e0d\u540c\u7684\u6837\u5f0f\u63a7\u5236\u3002<\/p>\n<div class=\"zxx_code\">\n<pre>.my-element {\n  background-image: url(image.svg);\n}\n.no-svg .my-element {\n  background-image: url(image.png);\n}<\/pre>\n<\/div>\n<p>\u8fd9\u6837\u5c31\u4e0d\u4f1a\u51fa\u73b0\u53cc\u4e0b\u8f7d\u7684\u95ee\u9898\u4e86\u3002<\/p>\n<p>\u4f46\u662f\uff0cModernizr\u6bd5\u7adf\u662f\u4e2a\u5916\u90e8\u4f9d\u8d56\uff0c\u4e14\u8c8c\u4f3c\u8198\u80a5\u4f53\u952e\uff0c\u771f\u8981\u5b9e\u9645\u5e94\u7528\uff0c\u4e0d\u5408\u9002\u7684\u6765~<\/p>\n<p>\u4e0b\u9762\u6709\u4e2a\u66f4\u4f18\u7684\u65b9\u6cd5\uff0c\u5229\u7528CSS\u652f\u6301\u7684\u4f2ahack\uff0c\u5982\u4e0b\u4f7f\u7528\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>.my-element {\n  background-image: url(fallback.png);\n  background-image: url(image.svg), none;\n}<\/pre>\n<\/div>\n<p>\u5176\u5229\u7528\u7684\u6280\u672f\u662fCSS3\u591a\u80cc\u666f\uff0c\u8fd9\u662f\u4e00\u4e2a\u7ecf\u9a8c\u5f0f\u6280\u672f\uff0c\u6211\u4eec\u901a\u8fc7\u5404\u79cd\u89c2\u5bdf\u6216\u8005\u79ef\u7d2f\u53d1\u73b0\uff0c\u6d4f\u89c8\u5668\u53ea\u8981\u652f\u6301\u4e86\u591a\u80cc\u666f\uff0c\u51e0\u4e4e\u65e0\u4e00\u4f8b\u5916\u652f\u6301SVG. \u4e8e\u662f\uff0c\u6d4f\u89c8\u5668\u8ba4\u8bc6<code>url(image.svg), none<\/code>\u8fd9\u4e2a\u591a\u80cc\u666f\u58f0\u660e\uff0c\u5c31\u4f7f\u7528SVG\uff0c\u5426\u5219\uff0c\u964d\u7ea7\u4f7f\u7528\u4e0a\u9762\u7684<code>png<\/code>\u80cc\u666f\u3002\u5f88\u8d5e\u7684match~<\/p>\n<p>\u7c7b\u4f3c\u6280\u672f\uff0c\u6211\u4e4b\u524d\u4e5f\u4ecb\u7ecd\u8fc7\uff0c\u7a0d\u7b49\uff0c\u8ba9\u6211\u627e\u627e~<\/p>\n<p>Get it! \u6b64\u6587\u4e3a\uff1a\u201c<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=1867\">\u5c0ftip:\u5de7\u7528CSS3\u5c5e\u6027\u4f5c\u4e3aCSS hack<\/a>\u201d\u3002\u4e24\u5e74\u591a\u524d\u7684\u4e86\uff0c\u550f\u5618\u611f\u53f9\u65f6\u95f4\u6d41\u901d\u4e4b\u5feb\u554a~~<\/p>\n<p><strong>2. \u5982\u679c\u4f60\u4f7f\u7528SVG\u4f5c\u4e3a&lt;svg&gt;<\/strong><br \/>\n\u9996\u63a8\u672c\u6587\u4e00\u5f00\u59cb\u4ecb\u7ecd\u7684&lt;image&gt;\u6280\u672f\uff0c\u5bf9\u4e8e<code>inline<\/code> SVG\u8f7b\u5fae\u7684\u964d\u4f4e\u652f\u6301\u95ee\u9898(\u6307\u9488\u5bf9ios3\/ios4)\u8bbe\u5907\uff0c\u6211\u4e2a\u4eba\u89c9\u5f97\u5927\u53ef\u4e0d\u5fc5\u5728\u610f\u3002<\/p>\n<div class=\"zxx_code\">\n<pre>&lt;svg width=\"96\" height=\"96\">\n  &lt;image xlink:href=\"svg.svg\" src=\"svg.png\" width=\"96\" height=\"96\" \/>\n&lt;\/svg><\/pre>\n<\/div>\n<p>David Ensinger<a href=\"http:\/\/davidensinger.com\/2013\/04\/inline-svg-with-png-fallback\/\">\u53d1\u8868\u8fc7\u4e00\u9879\u6280\u672f<\/a>\uff0c\u662f\u5728SVG\u4e2d\u4f7f\u7528<code>&lt;foreignObject&gt;<\/code>\u6807\u7b7e\u3002\u5448\u73b0\u6548\u679c\u8fd8\u4e0d\u8d56\uff0c\u4f46\u95ee\u9898\u662f\uff0c\u65e0\u8bba\u54ea\u4e2a\u6d4f\u89c8\u5668\uff0c\u4ff1\u8fdb\u6d3e\u8fd8\u662f\u987d\u56fa\u6d3e\u90fd\u4f1a\u4e0b\u8f7d\u964d\u7ea7\u7684PNG\u56fe\u7247\uff0c\u8fd9\u663e\u7136\u6ca1\u6709\u4e0a\u9762\u7684&lt;image&gt;\u6280\u672f\u667a\u80fd\u3002<\/p>\n<p>\u5f53\u7136\uff0c\u4f60\u8fd8\u53ef\u4ee5\u501f\u52a9Modernizr\u505a\u4e9b\u66f4\u52a0\u7075\u6d3b\u7684\u5904\u7406\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>&lt;svg> ... inline SVG XXX ... &lt;\/svg>\n&lt;div class=\"my-svg-alternate\">&lt;\/div><\/pre>\n<\/div>\n<div class=\"zxx_code\">\n<pre>.my-svg-alternate {\n  display: none;\n}\n.no-svg .my-svg-alternate {\n  display: block;\n  width: 96px;\n  height: 96px;\n  background-image: url(image.png);\n}<\/pre>\n<\/div>\n<p><strong>3. \u5982\u679c\u4f60\u4f7f\u7528SVG\u4f5c\u4e3a&lt;object&gt;<\/strong><br \/>\n\u4f7f\u7528<code>&lt;object&gt;<\/code>\u6807\u7b7e\u4f5c\u4e3aSVG\u5143\u7d20\u672c\u8eab\uff0c\u5bf9\u4e8e\u4e0d\u652f\u6301\u6d4f\u89c8\u5668\uff0c\u8fd8\u662f\u9700\u8981Modernizr\u6216\u81ea\u5df1\u5199\u4e2a\u5224\u65ad\uff0c\u6216\u8005\u81ea\u5df1\u7ecf\u9a8c\u7684\u6d4f\u89c8\u5668\u5224\u65ad\u5b9e\u73b0\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>&lt;object type=\"image\/svg+xml\" data=\"image.svg\" class=\"logo\">&lt;\/object><\/pre>\n<\/div>\n<div class=\"zxx_code\">\n<pre>.no-svg .logo {\n  display: block;\n  width: 96px;\n  height: 96px;\n  background-image: url(image.png);\n}<\/pre>\n<\/div>\n<p><strong>4. \u5982\u679c\u4f60\u4f7f\u7528SVG\u4f5c\u4e3a&lt;img&gt;<\/strong><br \/>\nScott Jehl<a href=\"https:\/\/twitter.com\/scottjehl\/status\/369190249437483008\">\u559c\u6b22\u8fd9\u4e48\u505a<\/a>\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>&lt;img src=\"image.svg\" onerror=\"this.src=image.png\"><\/pre>\n<\/div>\n<p>HTML\u6df7\u6742\u884c\u4e3a\uff0c\u5982\u679c\u4f60\u662f\u4e2a\u5177\u6709\u5206\u79bb\u7656\u597d\u7684\u4eba\uff0c\u4e0a\u9762\u7684\u65b9\u6cd5\u53ef\u80fd\u4f1a\u8ba9\u4f60\u63ea\u5fc3\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5Modernizr\u7684JS API\uff0c\u5728\u811a\u672c\u4e2d\u5224\u65ad\u5904\u7406\uff0c\u7c7b\u4f3c\u4e0b\u9762\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>if (!Modernizr.svg) {\n  $(\"img[src$='.svg']\").attr(\"src\", fallback);\n}<\/pre>\n<\/div>\n<p>\u5982\u679c\u4e0a\u9762\u4ee3\u7801\u4e2d\u7684<code>fallback<\/code>\u662f\u4e2aURL\u5b57\u7b26\u4e32\uff0c\u4f60\u53ef\u4ee5\u628a\u8fd9\u4e2a\u5b57\u7b26\u4e32\u653e\u5728<code>data-fallback<\/code>\u4e2d\uff0c\u7136\u540e\uff0c\u4f60\u5c31\u53ef\u4ee5\u6839\u636e\u4f60\u7684\u5b9e\u9645\u9700\u8981\uff0c\u4f8b\u5982\uff0c\u6839\u636e\u540e\u7f00\u505a\u667a\u80fd\u5224\u65ad\u52a0\u8f7d\u7b49\u3002<\/p>\n<p><a href=\"http:\/\/benhowdle.im\/svgeezy\/\">SVGeezy<\/a>\u5c31\u662f\u4e2a\u4e13\u95e8\u505a\u8fd9\u79cd\u4e8b\u60c5\u7684JS\u5e93\u3002<\/p>\n<p>\u6216\u8005\uff0c\u4f60\u85cf\u4e2a\u9690\u85cf\u7684DIV\uff0c\u5728\u9700\u8981\u964d\u7ea7\u663e\u793a\u7684\u65f6\u5019\u5c31\u663e\u793a\uff0c\u4e0a\u9762\u6709\u51fa\u73b0\u8fc7\u2026\u2026<\/p>\n<h3>\u56db\u3001SVG\u7ed3\u8bed<\/h3>\n<p>\u4ece\u6700\u8fd1\u6211\u5bf9\u56fd\u5916\u4e00\u4e9b\u77e5\u540d\u524d\u7aef\u7f51\u7ad9\u7684\u6587\u7ae0\u89c2\u5bdf\u6765\u770b\uff0cSVG\u76f8\u5173\u7684\u5185\u5bb9\u6bd4\u91cd\u8d8a\u6765\u8d8a\u5927\uff0c\u53bb\u5e74\u662f\u6ee1\u5c4f\u7684\u54cd\u5e94\u5f0f\uff0cSO\uff0c\u6211\u4f3c\u4e4e\u55c5\u5230\u4e86\u4e00\u70b9\u6280\u672f\u6d41\u884c\u8d8b\u52bf\u7684\u5473\u9053\u3002\u56fd\u5185\u524d\u7aef\u6280\u672f\u7684\u6d41\u884c\u666e\u904d\u5177\u6709\u6ede\u540e\u6027\uff0c\u5dee\u4e0d\u591a1~2\u5e74\u7684\u6837\u5b50\u3002\u56e0\u6b64\uff0c\u672c\u6587\u5185\u5bb9\uff0c\u5bf9\u4e8e\u5f88\u5927\u4e00\u90e8\u5206\u540c\u884c\u800c\u8a00\uff0c\u53ef\u80fd\u5c31\u662f\u201c\u54e6~\u201d\u4e00\u4e0b\uff0c\u4e0d\u6253\u7d27\u3002\u60a8\u53ef\u4ee5\u5148\u8bb0\u4f4f\u8fd9\u91cc\uff0c\u7b49\u660e\u5e74\u8fd9\u4e2a\u65f6\u5019\uff0c\u6216\u8005\u660e\u5e74\u7684\u660e\u5e74\u7684\u8fd9\u4e2a\u65f6\u5019\uff0c\u5f53\u4f60\u53d1\u73b0\u4f60\u8981\u6298\u817eSVG\u7684\u65f6\u5019\uff0c\u518d\u6765\u56f4\u89c2\u56f4\u89c2\uff0c\u5e0c\u671b\u5230\u65f6\uff0c\u672c\u6587\u7684\u4e00\u4e9b\u5c0f\u6280\u672f\u4e0d\u4f1a\u8fc7\u65f6\uff0c(*^__^*) \u563b\u563b\u2026\u2026<\/p>\n<p>\u611f\u8c22\u9605\u8bfb\uff0c\u6b22\u8fce\u7ea0\u9519\uff01<\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u6765\u81ea<a href=\"http:\/\/www.zhangxinxu.com\/\">\u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b<\/a>[<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=3678\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=3678<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5bf9SVG\u6709\u6240\u5173\u6ce8\u7684\u540c\u884c\u5e94\u8be5\u90fd\u77e5\u9053\uff0cIE8-\u4ee5\u53caAndroid 2.3\u9ed8\u8ba4\u6d4f\u89c8\u5668\u662f\u4e0d\u652f\u6301SVG\u7684\uff0c\u5b9e\u9645\u9879\u76ee\uff0c\u8fd9\u4e9b\u6d4f\u89c8\u5668\uff0c\u81f3\u5c11IE8\u6d4f\u89c8\u5668\u8fd8\u6ca1\u6709\u5230\u4e0d\u7ba1\u4e0d\u95ee\u7684\u65f6\u5019\uff0c\u56e0\u6b64\uff0c\u5728\u4f7f\u7528\u89c6\u7f51\u819c\u663e\u793a\u53cb\u597d\u7684SVG\u540c\u65f6\uff0c\u6211\u4eec\u8fd8\u8981\u505a\u4e00\u70b9\u4f18\u96c5\u964d\u7ea7\uff0c\u4f7fIE8\u7b49\u8003\u53e4\u4ef7\u503c\u6d4f\u89c8\u5668\u4e5f\u80fd\u624b\u67d3\u4f59\u9999\u3002<\/p>\n<p>\u672c\u6587\u5728\u4ecb\u7ecd\u4e00\u79cd\u65b0\u7684SVG\u964d\u7ea7\u6280\u672f\u7684\u540c\u65f6\uff0c\u540c\u65f6\u628a\u4ee5\u524dcss-tricks\u4e2d\u63d0\u5230\u7684\u6280\u672f\u53c8\u603b\u7ed3\u4e86\u4e00\u904d\u3002\u5927\u96c6\u5408\u4ec0\u4e48\u7684\u6211\u505a\u559c\u6b22\u4e86\uff0c\u4ee5\u540e\u4e0d\u8981\u627e\u6765\u627e\u53bb\uff0c\u56e0\u6b64\uff0c\u8fd9\u91cc\uff0c\u6211\u6309\u7167\u4e2a\u4eba\u7684\u7406\u89e3\uff0c\u914d\u5408\u81ea\u5df1\u7684\u4e00\u4e9b\u5b9e\u9645\u6d4b\u8bd5\uff0c\u5206\u4eab\u4e0b\u3002<\/p>\n<p>demo, \u622a\u56fe\u3001\u8868\u683c\u3001\u6e90\u4ee3\u7801\u4ec0\u4e48\u7684\u5e94\u6709\u5c3d\u6709\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":[737,10,642,866,381],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/3678"}],"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=3678"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/3678\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=3678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=3678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=3678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}