是否可以在单独的 svg 中“使用”整个其他 svg?我想使用 d3 生成的地图作为同一页面上的图标。这是我尝试过但不起作用的方法。
<svg id="map">
svg stuff here
</svg>
<svg id="bar">
svg stuff here
<use xlink:href="#map" height="20" width="30" ...>
</svg>
Run Code Online (Sandbox Code Playgroud)
还尝试了克隆方法,但最终在另一个 svg 中包含了整个 svg 并且无法扩展。例如。makeicon("#map", "#icon")
function makeicon(source, destination) {
//https://groups.google.com/forum/?fromgroups=#!topic/d3-js/-EEgqt29wmQ
var src = d3.select(source);
var dest = d3.select(destination);
if (!src.empty() && !dest.empty()) {
var newNode = d3.select(dest.node().insertBefore(src.node().cloneNode(true),
src.node().nextSibling))
.attr("id", "newnode")
.attr("width", null) // remove height and width of original svg
.attr("height", null)
.attr("viewBox", "0 0 20 30"); // try to make it smaller
return newNode;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5302 次 |
| 最近记录: |