的SVG環繞多邊形一「格」的標籤,這是例如我的SVG代碼..如何使用jQuery
<rect x="1531.718" y="1688.217" opacity="0.8" fill="#FEE880" enable-background="new " width="40.67" height="27"></rect>
<rect x="1531.718" y="1661.217" opacity="0.8" fill="#F67B9E" enable-background="new" width="40.67" height="27"></rect>
<rect x="1335.718" y="1053.356" opacity="0.8" fill="#FEE880" enable-background="new" width="236.67" height="153.01"></rect>
<polygon opacity="0.8" fill="#F67B9E" enable-background="new " points="1572.388,970.547 1572.388,1016.547
1509.718,1016.547 "></polygon>
我怎樣才能獲得的位置,寬度&高度時,一個div包裹圍繞着svg中的多邊形。我更喜歡使用jQuery。
我爲svg中的「rect」做了這個,它的作用像魅力! :)繼承人的代碼:
$('#mapArea').load('src/124/124.svg', function(){
var inputs = $('#mapArea').find('rect');
var inputsCount = inputs.size();
for (i=1;i<inputsCount;i++){
var positionX = $('#mapArea').find('rect:eq('+i+')').attr('x');
var positionY = $('#mapArea').find('rect:eq('+i+')').attr('y');
var width = $('#mapArea').find('rect:eq('+i+')').attr('width');
var height = $('#mapArea').find('rect:eq('+i+')').attr('height');
$('#mapArea').after('<div style="position:absolute;width:'+width+'px;height:'+height+'px;background:rgba(0,0,0,0.4);top:'+positionY+'px;left:'+positionX+'px;">');
}
我不能這樣做rect,因爲對於多邊形theres只有一個attr ...點!我該怎麼辦 ? :(