我用 Google 搜索了这个问题大约 30 分钟,很惊讶没有人问过,所以也许这是不可能的。
我使用这一行嵌入我在 AI 中制作的 SVG 文件(请注意,当我保存 SVG 时,路径上没有填充或描边):
<object type="image/svg+xml" data="example.svg" height=600px width=600px>Your browser does not support SVG</object>
这显然没有图像,因为 SVG 文件没有填充或描边。
我尝试添加
...fill=yellow>
or
...style="fill:yellow;">
但我没有任何运气。谢谢!
有一个不错的技巧:将其嵌入为<img>
并使用javascript将其转换为内联<svg>
使用这段代码(我认为来自SO)。现在您可以操作这个 SVG 对象
CODE::
/*
* Replace all SVG images with inline SVG
*/
jQuery('img.svg').each(function(){
var $img = jQuery(this);
var imgID = $img.attr('id');
var imgClass = $img.attr('class');
var imgURL = $img.attr('src');
jQuery.get(imgURL, function(data) {
// Get the SVG tag, ignore the rest
var $svg = jQuery(data).find('svg');
// Add replaced image's ID to the new SVG
if(typeof imgID !== 'undefined') {
$svg = $svg.attr('id', imgID);
}
// Add replaced image's classes to the new SVG
if(typeof imgClass !== 'undefined') {
$svg = $svg.attr('class', imgClass+' replaced-svg');
}
// Remove any invalid XML tags as per http://validator.w3.org
$svg = $svg.removeAttr('xmlns:a');
// Replace image with new SVG
$img.replaceWith($svg);
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)