2016-07-06 197 views
1

懸停時是否可以添加帶有svg多邊形形狀的文本?懸停在SVG中的多邊形上顯示文本

我這樣的代碼

<svg> 
 
    <polygon class="st0" points="0,1.833 638,1.833 383,348.833 0,348.833 "/> 
 
    <polygon class="st0" points="0,355.333 649,355.333 891.5,664.833 0,664.833 "/> 
 
    <polygon class="st0" points="392.5,348.833 514.75,181.333 645.25,348.833 "/> 
 
    <polyline class="st0" points="518.875,174.908 644.667,2.021 1139.833,1.52 1139.75,663.583 897.25,663.583 "/> 
 
    </svg>

當我檢查過很多的參考,只有單個多邊形的例子,但在我的代碼需要4個形狀不同的文本一個SVG標籤。有可能添加文字懸停與多個多邊形?

Here a fiddle what I have

當我將鼠標懸停我想這樣 enter image description here

任何意見,將不勝感激

+0

什麼樣的「文本」?目前還不清楚你想要做什麼。 –

+0

@Paulie_D懸停文字。很明顯!閱讀問題標題 – Suresh

回答

3

呦可以添加

<title>Your text</title> 

標籤內<svg></svg><poligon></poligon>標籤顯示默認工具提示上有文字。

更新jsfiddle

來源:

.st0 { 
 
    fill: #0491B7; 
 
} 
 
.st1 { 
 
    fill: #0491B7; 
 
} 
 
.st1:hover { 
 
    fill: red; 
 
    opacity: 0.5; 
 
} 
 
.st0:hover { 
 
    fill: red; 
 
} 
 

 
text{ 
 
    display:none; 
 
    fill:#fff; 
 
    font-size:2em; 
 
    font-family:sans-serif; 
 
} 
 

 
text.sub-text{ 
 
    display:none; 
 
    fill:#fff; 
 
    font-size:0.8em; 
 
    font-family:sans-serif; 
 
} 
 

 
g:hover > text{ 
 
    display:block; 
 
}
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1139.833px" height="663.313px" viewBox="0 0 1139.833 663.313" style="enable-background:new 0 0 1139.833 663.313;" xml:space="preserve"> 
 
    
 
    <g> 
 
    <polygon class="st0" points="0,0.313 638,0.313 383,347.313 0,347.313 "> 
 
    <title>One</title> 
 
    </polygon> 
 
    <text x="10" y="40"> TITLE </text> 
 
    <text x="10" y="55" class="sub-text">Some Content</text> 
 
    </g> 
 

 
    <polygon class="st1" points="0,353.813 649,353.813 891.5,663.313 0,663.313 "> 
 
    <title>Two</title> 
 
    </polygon> 
 

 
    <polygon class="st0" points="392.5,347.313 514.75,179.813 645.25,347.313 "> 
 
    <title>Three</title> 
 
    </polygon> 
 

 
    <polyline class="st0" points="518.875,173.388 644.667,0.501 1139.833,0 1139.75,662.063 897.25,662.063"> 
 
    <title>Four</title> 
 
    </polyline> 
 
</svg>

+1

@ user5533614完成!!! – Suresh

+1

雅,它岩石..謝謝@eirenaios – Twinxz