我有一個格式爲.svg的圖像,如下所示。與.svg圖像交互
我想打一個網頁,用戶可以用這樣的圖像互動,但更多的節點。該結構將類似於樹。
是否可以使用javascript/html/css直接與此.svg圖像交互?
如果是這樣,怎麼樣?
注意:通過交互,我的意思是能夠點擊節點並識別網頁 - 當選擇了一個節點時,其他節點的顏色會發生變化。注意2:我只有.svg文件,我不知道是否可以將它定義爲html上的內聯svg。注意3:這個圖像將有很多節點(80+),所以我寧願不必爲每個節點定義一個可點擊的區域,等等......但是如果這是唯一的解決方案,沒有問題。
編輯: 這裏是我的.svg文件的內容:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.38.0 (20140413.2041)
-->
<!-- Title: g Pages: 1 -->
<svg width="134pt" height="116pt"
viewBox="0.00 0.00 134.00 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 112)">
<title>g</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-112 130,-112 130,4 -4,4"/>
<!-- a -->
<g id="node1" class="node"><title>a</title>
<ellipse fill="none" stroke="black" cx="27" cy="-90" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-86.3" font-family="Times New Roman,serif" font-size="14.00">a</text>
</g>
<!-- b -->
<g id="node2" class="node"><title>b</title>
<ellipse fill="none" stroke="black" cx="27" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-14.3" font-family="Times New Roman,serif" font-size="14.00">b</text>
</g>
<!-- a->b -->
<g id="edge1" class="edge"><title>a->b</title>
<path fill="none" stroke="black" d="M27,-71.6966C27,-63.9827 27,-54.7125 27,-46.1124"/>
<polygon fill="black" stroke="black" points="30.5001,-46.1043 27,-36.1043 23.5001,-46.1044 30.5001,-46.1043"/>
</g>
<!-- c -->
<g id="node3" class="node"><title>c</title>
<ellipse fill="none" stroke="black" cx="99" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="99" y="-14.3" font-family="Times New Roman,serif" font-size="14.00">c</text>
</g>
<!-- b->c -->
<g id="edge2" class="edge"><title>b->c</title>
<path fill="none" stroke="black" d="M54,-18C56.6147,-18 59.2295,-18 61.8442,-18"/>
<polygon fill="black" stroke="black" points="61.9297,-21.5001 71.9297,-18 61.9297,-14.5001 61.9297,-21.5001"/>
</g>
</g>
</svg>
如果你什麼都不知道,你應該從一本書開始,而不是一個真正的普遍問題。試試這個http://www.w3。org/Graphics/SVG/IG/resources/svgprimer.html –
感謝您的建議。 到目前爲止,我只是看着與svg圖像交互有多複雜。我甚至不確定我是否真的會按照我的想法去做。另外,我打算做的並不是很複雜,我只需要知道哪些節點被選中,並根據這些節點改變某些節點的顏色。看過@Paulie_D代碼後,我可能會在這個週末嘗試一下。 :) – Xaphanius