2

我有一个 svg 文件并使用 Raphael 库。我的 svg 文件包含以下样式:

<defs>
  <style type="text/css">
   <![CDATA[
    .fil1 {fill:#2B2A29}
    .fil0 {fill:#009846;fill-opacity:1}
    .fnt0 {font-weight:bold;font-size:10.9996;font-family:'Arial'}
   ]]>
  </style>
  <filter id="Filter" filterUnits="userSpaceOnUse" x="0" y="0" width="660" height="400">
    <feGaussianBlur in="SourceAlpha" stdDeviation="3" result="blur"/>
    <feOffset in="blur" dx="0" dy="3" result="offsetBlur"/>
    <feMerge>
        <feMergeNode in="offsetBlur"/>
        <feMergeNode in="SourceGraphic"/>
    </feMerge>
  </filter>
 </defs>

Raphael使用在线工具将此 svg 文件转换为I。这个工具没有插入我的风格。我得到以下标记:

<svg height="400" version="1.1" width="660" xmlns="http://www.w3.org/2000/svg" style="overflow: hidden; position: relative;"><desc>Created with RaphaГ«l 2.1.0</desc><defs/><path style="stroke-opacity: 1;" fill="#000000" stroke="#000000" d="M296,116L297,118L343,124L375,105L366,94L339,88L320,98L319,98Z" stroke-width="0" stroke-opacity="1"/>

...

如您所见,defs标签为空。

我尝试手动添加样式:

$('defs').append('<style type="text/css"><![CDATA[.fil1 {fill:#2B2A29}.fil0 {fill:#009846;fill-opacity:1}.fnt0 {font-weight:bold;font-size:10.9996;font-family:'Arial'}]]></style><filter id="Filter" filterUnits="userSpaceOnUse" x="0" y="0" width="660" height="400"><feGaussianBlur in="SourceAlpha" stdDeviation="3" result="blur"/><feOffset in="blur" dx="0" dy="3" result="offsetBlur"/><feMerge><feMergeNode in="offsetBlur"/><feMergeNode in="SourceGraphic"/></feMerge></filter>');

但是,我得到错误:

missing ) after argument list

...ght:bold;font-size:10.9996;font-family:'Arial'}]]></style><filter id="Filter" fi...

如何正确获取 svg 样式并附加Raphael

4

0 回答 0