我可以使用URL通过D3.js轻松插入SVG图像,如下所示:
var img = g.append("svg:image")
.attr("xlink:href", "http://www.clker.com/cliparts/1/4/5/a/1331068897296558865Sitting%20Racoon.svg")
.attr("width", 200)
.attr("height", 200)
.attr("x", 228)
.attr("y",53);
但是,我在网上无处不在,并尝试了我能想到的一切,但我无法使用本地图像参考(绝对路径或相对路径)进行相同操作,这让我发疯了
答案 0 :(得分:0)
我的版本(有效):
CSS:
iframe {
top: 0;
left: 0;
height: 200px;
width: 200px;
border-width: 0px;
/* background-color: #B0B0B0; */
border: none;
}
JS:
(function () {
// Prevent White Flash While iFrame Loads. Prevent variables from being global.
// 1. Inject CSS which makes iframe invisible
var div = document.createElement('div'),
ref = document.getElementsByTagName('base')[0]
|| document.getElementsByTagName('script')[0];
div.innerHTML = '­<style> iframe { visibility: hidden; } </style>';
ref.parentNode.insertBefore(div, ref);
// 2. When window loads, remove that CSS, making iframe visible again
window.onload = function() {
div.parentNode.removeChild(div);
}
})();
HTML:
<iframe src="image\hour-glass.svg" scrolling="no" align="bottom"></iframe>
答案 1 :(得分:-2)