And*_*rés 7 svg gradient symbols linear-gradients fill
我有一个带有<symbol>trhat的 svg 精灵,其中包含一个<linearGradient>. 我在提出<g>这个相同的<symbol>这一梯度的fill="url(#id)"。但是,当我在其他文档中加载<symbol>with<use>时,<linearGradient>不会加载。我可以看到填充的 url 指的是绝对路径而不是文档内部,并且没有正确加载。
如何<linearGradient>在 a 中加载a <symbol>?
<symbol viewBox="0 0 550 90" width="100%" height="100%">
<defs>
<linearGradient id="gradient">
<stop offset="-1.04974" stop-color="#D8D8D8">
<animate attributeName="offset" values="-2; 1" dur="1s" repeatCount="indefinite"></animate>
</stop>
<stop offset="-0.549739" stop-color="#EEEEEE">
<animate attributeName="offset" values="-1.5; 1.5" dur="1s" repeatCount="indefinite"></animate>
</stop>
<stop offset="-0.0497395" stop-color="#D8D8D8">
<animate attributeName="offset" values="-1; 2" dur="1s" repeatCount="indefinite"></animate>
</stop>
</linearGradient>
</defs>
<g fill="url(#gradient)">
<rect x="0" y="0" width="100" height="15"/>
<rect x="10" y="25" width="130" height="15" />
</g>
</symbol>
Run Code Online (Sandbox Code Playgroud)
War*_*ama -1
正如评论中指出的,linearGradient将symbol.
这是一个有效的修改示例:
<svg style="visibility:hidden; width: 0; height: 0;">
<defs>
<linearGradient id="gradient">
<stop offset="-1.04974" stop-color="#D8D8D8">
<animate attributeName="offset" values="-2; 1" dur="1s" repeatCount="indefinite"></animate>
</stop>
<stop offset="-0.549739" stop-color="#EEEEEE">
<animate attributeName="offset" values="-1.5; 1.5" dur="1s" repeatCount="indefinite"></animate>
</stop>
<stop offset="-0.0497395" stop-color="#D8D8D8">
<animate attributeName="offset" values="-1; 2" dur="1s" repeatCount="indefinite"></animate>
</stop>
</linearGradient>
<symbol id="symbol1" viewBox="0 0 550 90" width="100%" height="100%">
<g fill="url(#gradient)">
<rect x="0" y="0" width="100" height="15"/>
<rect x="10" y="25" width="130" height="15" />
</g>
</symbol>
</defs>
</svg>
<svg width="400" height="400">
<use xlink:href="#symbol1"></use>
</svg>Run Code Online (Sandbox Code Playgroud)