demo_symbol.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <title>IconFont</title>
  6. <link rel="stylesheet" href="demo.css">
  7. <script src="iconfont.js"></script>
  8. <style type="text/css">
  9. .icon {
  10. /* 通过设置 font-size 来改变图标大小 */
  11. width: 1em; height: 1em;
  12. /* 图标和文字相邻时,垂直对齐 */
  13. vertical-align: -0.15em;
  14. /* 通过设置 color 来改变 SVG 的颜色/fill */
  15. fill: currentColor;
  16. /* path 和 stroke 溢出 viewBox 部分在 IE 下会显示
  17. normalize.css 中也包含这行 */
  18. overflow: hidden;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div class="main markdown">
  24. <h1>IconFont 图标</h1>
  25. <ul class="icon_lists clear">
  26. <li>
  27. <svg class="icon" aria-hidden="true">
  28. <use xlink:href="#icon-jiantou2"></use>
  29. </svg>
  30. <div class="name">箭头-2</div>
  31. <div class="fontclass">#icon-jiantou2</div>
  32. </li>
  33. <li>
  34. <svg class="icon" aria-hidden="true">
  35. <use xlink:href="#icon-xuanzhong"></use>
  36. </svg>
  37. <div class="name">选中</div>
  38. <div class="fontclass">#icon-xuanzhong</div>
  39. </li>
  40. <li>
  41. <svg class="icon" aria-hidden="true">
  42. <use xlink:href="#icon-error"></use>
  43. </svg>
  44. <div class="name">error</div>
  45. <div class="fontclass">#icon-error</div>
  46. </li>
  47. <li>
  48. <svg class="icon" aria-hidden="true">
  49. <use xlink:href="#icon-prompt"></use>
  50. </svg>
  51. <div class="name">prompt</div>
  52. <div class="fontclass">#icon-prompt</div>
  53. </li>
  54. <li>
  55. <svg class="icon" aria-hidden="true">
  56. <use xlink:href="#icon-success"></use>
  57. </svg>
  58. <div class="name">success</div>
  59. <div class="fontclass">#icon-success</div>
  60. </li>
  61. <li>
  62. <svg class="icon" aria-hidden="true">
  63. <use xlink:href="#icon-help"></use>
  64. </svg>
  65. <div class="name">help</div>
  66. <div class="fontclass">#icon-help</div>
  67. </li>
  68. <li>
  69. <svg class="icon" aria-hidden="true">
  70. <use xlink:href="#icon-weixuanzhong"></use>
  71. </svg>
  72. <div class="name">未选中</div>
  73. <div class="fontclass">#icon-weixuanzhong</div>
  74. </li>
  75. </ul>
  76. <h2 id="symbol-">symbol引用</h2>
  77. <hr>
  78. <p>这是一种全新的使用方式,应该说这才是未来的主流,也是平台目前推荐的用法。相关介绍可以参考这篇<a href="">文章</a>
  79. 这种用法其实是做了一个svg的集合,与另外两种相比具有如下特点:</p>
  80. <ul>
  81. <li>支持多色图标了,不再受单色限制。</li>
  82. <li>通过一些技巧,支持像字体那样,通过<code>font-size</code>,<code>color</code>来调整样式。</li>
  83. <li>兼容性较差,支持 ie9+,及现代浏览器。</li>
  84. <li>浏览器渲染svg的性能一般,还不如png。</li>
  85. </ul>
  86. <p>使用步骤如下:</p>
  87. <h3 id="-symbol-">第一步:引入项目下面生成的symbol代码:</h3>
  88. <pre><code class="lang-js hljs javascript"><span class="hljs-comment">&lt;script src="./iconfont.js"&gt;&lt;/script&gt;</span></code></pre>
  89. <h3 id="-css-">第二步:加入通用css代码(引入一次就行):</h3>
  90. <pre><code class="lang-js hljs javascript">&lt;style type=<span class="hljs-string">"text/css"</span>&gt;
  91. .icon {
  92. width: <span class="hljs-number">1</span>em; height: <span class="hljs-number">1</span>em;
  93. vertical-align: <span class="hljs-number">-0.15</span>em;
  94. fill: currentColor;
  95. overflow: hidden;
  96. }
  97. &lt;<span class="hljs-regexp">/style&gt;</span></code></pre>
  98. <h3 id="-">第三步:挑选相应图标并获取类名,应用于页面:</h3>
  99. <pre><code class="lang-js hljs javascript">&lt;svg <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"icon"</span> aria-hidden=<span class="hljs-string">"true"</span>&gt;<span class="xml"><span class="hljs-tag">
  100. &lt;<span class="hljs-name">use</span> <span class="hljs-attr">xlink:href</span>=<span class="hljs-string">"#icon-xxx"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">use</span>&gt;</span>
  101. </span>&lt;<span class="hljs-regexp">/svg&gt;
  102. </span></code></pre>
  103. </div>
  104. </body>
  105. </html>